In part two of this ten part series, I discussed some basic Java language syntax. In this article, I will discuss some of the Java primitive types and describe the basics of a Java class. I will also touch on the JDK (Java Development Kit) and describe how to compile a small class.
After installing the software, run through the documentation to make sure that you've set it up correctly. The JDK should now be ready to use. If you are encountering any problems, refer back to the documentation provided with the JDK.
To compile our example, we will need to save the example class that we have developed into a file named Number.java. When you create a class in a file, the filename has to match the name of the class. Save the file into a new directory, separate from your Java installation directory, c:\javacode, for example.
Java code is compiled, meaning that your source code file, Number.java is converted into byte-code. The Java Virtual Machine then executes the byte-code. To compile our class file, we use the javac program, as follows:
This will compile your .java file into a .class file, which is now ready to run. To run your application, simply type the following line at the DOS prompt or Unix command line:
Do not type Java Number.class. You donít need to specify the .class extension! And there you have it, you have created your first Java application.