Java Reference
In-Depth Information
1.8 The Compilation Process
Some Java development environments are very convenient to use. Enter the code in
one window, click on a button to compile, and click on another button to execute your
program. Error messages show up in a second window, and the program runs in a third
window. With such an environment you are completely shielded from the details of the
compilation process. On other systems you must carry out every step manually, by
typing commands into a shell window.
No matter which compilation environment you use, you begin your activity by typing
in the program statements. The program that you use for entering and modifying the
program text is called an editor. Remember to save your work to disk frequently,
because otherwise the text editor stores the text only in the computer's memory. If
something goes wrong with the computer and you need to restart it, the contents of the
primary memory (including your program text) are lost, but anything stored on the
hard disk is permanent even if you need to restart the computer.
An editor is a program for entering and modifying text, such as a Java program.
When you compile your program, the compiler translates the Java source code (that is,
the statements that you wrote) into class files, which consist of virtual machine
instructions and other information that is required for execution. The class files have
the extension .class . For example, the virtual machine instructions for the
Hello-Printer program are stored in a file HelloPrinter.class . As already
mentioned, the compiler produces a class file only after you have corrected all syntax
errors.
The Java compiler translates source code into class files that contain instructions for
the Java virtual machine.
The class file contains the translation of only the instructions that you wrote. That is
not enough to actually run the program. To display a string in a window, quite a bit of
low-level activity is necessary. The authors of the System and PrintStream
classes (which define the out object and the println method) h ave implemented all
necessary actions and placed the required class files into a library . A library is a
25
26
Search WWH ::




Custom Search