Program in Java
To program in Java (not JavaScript, an unrelated language), you need a compiler, a program to convert Java source code to bytecode. In the old days, the only option was Sun's JDK; but now you have many options, including the GNU GCJ which creates class files or native exe files, and jikes, IBM's open source contribution. You also will need a Java virtual machine, which is a "machine within a machine" which understands Java bytecodes and translates them into machine language on the target processor. There are many available, but you can never go wrong with the javac compiler and java JRE virtual machine included with Sun's Java standard edition.
Steps
- Download the correct package for your platform. Windows and Solaris users should visit Oracle's Java SE page to download a package, Macintosh users will find they already have the Java SE installed. For maximum portability, it may be better to get an older edition; not all your potential users will have the latest JVM installed. Alternatively, use an open-source or other third-party compiler such as GCJ or jikes, and compile to a native executable or run it with the Java JRE.
- Learn to use an IDE. Eclipse and NetBeans are two of many other IDEs that are here to help us write the code easier -- they report any errors as you code, they help with methods, imports and many more.
- Learn Edit-Compile-Test cycle. You should start with the Hello World program.
- Create your own or edit other people's class(es).
- Compile to class file(s).
- Run the program with the Java executable, or as an applet in a browser. If the functionality isn't correct, or you want to add more features, start again at step 1.
- If you can afford it, buy a good book about Java programming and carefully read the beginning. With this language, the beginning is more difficult than later steps.
- Check out sites such as Cksstudios.com, Java Cooperation, Cokeandcode and Oracle's website for resources/tutorials.
- Take advantage of the object oriented paradigm. Learn how to use inheritance, classes, polymorphism and encapsulation to increase the efficiency of your code. Being object oriented is one of Java's strong points, so use it fully.
- Read up and follow a Java tutorial (one of the first recommended tutorials could be a tutorial on collections).
- For specific info on the classes, methods, and variables, visit Oracle's API
- If you face any problems, always try a web search. There are a lot of good articles about Java on the web.
- Don't reinvent the wheel. Java was always about reusing open-source libraries. If you need something that is not commonly used, there's usually a library that helps you.
Tips
- Keep your code organized and add lots of comments for easy reading, recalling, and updating.
- After you get some experience, try to get official programmer certification from Sun Microsystems itself. This is a lot more serious than any other certification you can get from the third parties.
- Learn technologies in which Java is strong: network communication, database connection, web development, etc.
- Remember to indent your code to make it readable. How much you indent will depend on your programming style, but as a general rule, leave a line and add a space after every curly bracket.
- Don't use "magic numbers" if you can help it. Magic numbers are numbers and values that are distributed through your code when they should be defined as a variable, so they can be reused, and explained in a comment so what they represent can be understood. This makes code easier to maintain and update.
- Unnecessarily long methods (the Java name for subroutines/functions) are looked down upon since they make your code hard to read and difficult to update. Learn to factor your code into small, precise modules that do one thing well.
- After you master the basics, try to join the existing open source project and work together with other people. From the viewpoint of learning, this is more efficient than to develop something large and complex by yourself.
- Go through the API's provided with the SDK. Make a habit of reading the description of the methods and classes. This will help you remember the method or class used the next time you need it.
- Master JUnit and write automatic tests that check the consistency of your program. Most serious projects do this.
- Bookboon has some good free books on Java for beginners
Warnings
- It is usually not necessary to pay for Java courses that may be very expensive and offer little value. Unless you want to learn something specific, it is frequently better just to do more programming yourself, and learn from other people's open-source programs.
Related Articles
- Install Java
- Install the Java Software Development Kit
- Make a Java Applet Animation With CarpStudio
- Program in Visual Basic .NET (VB.NET)
- Make a Placemat Purse
- Get Input from a User in Java
- Download Eclipse IDE on Windows Operating System
- Change Java Runtime
- Write a Program in Java to Calculate the Mean
- Write Java I/O