Java Part 3: Primitive Types - Compiling the Application
(Page 5 of 6 )
Before we can compile our example, we will need to install a working Java environment. We will use the JDK (Java Development Kit), which is a free download.
You can download the JDK for windows from
http://java.sun.com/j2se/1.3/download-windows.html. The JDK is also available for Linux from
http://java.sun.com/j2se/.
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:
javac Number.java
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:
java Number
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.
Next: Conclusion >>
More Java Articles
More By Chris Noack