The standard Java compiler is named javac and comes with the SDK. To compile a Java program, you type "javac," followed by any compiler options and the name of the source code to be compiled. javac <options> <source_code> You can specify more than one source file to be compiled. Table 1.1 lists the Java compiler options and what they do. You can also get this list by typing either "javac" or "javac “help." You will find that for many of your programs, you will simply use the javac keyword by itself without any options. Table 1.1. Java Compiler Options
The Java compiler is smart in that it will automatically compile any dependent source code. For example, let's say the Blah.java program makes use of source code contained in the Foo.java program. If you compile the Blah.java program by typing "javac Blah.java" the compiler will also, if necessary, compile the Foo.java code. The output of the Java compiler is the bytecode of the compiled program. The bytecode file name will have the same name of the source code sent to the compiler with the ".class" extension. For example, to compile the Blah .java source code without any compiler options you would type javac Blah.java This will generate a bytecode file named Blah.class . To run a Java program, you must send the appropriate bytecode to the JVM. You do this by typing "java," any JVM options, and the .class file name. java <options> <class_file> You do not type the .class extension. For example, to run the compiled Blah.java program without any JVM options, you would type ” java Blah Some of the more commonly used standard JVM options are listed in Table 1.2. Table 1.2. Virtual Machine Options
|