Figure 2-1 gives an overview of the Java project creation process.
As figure 2-1 suggests, the Java project-creation process consists of three stages: source-file creation stage, source-file compilation stage, and main-application execution stage. Each stage is covered in detail in the following sections.
Figure 2-1: Java Project Creation Process
In the source-file creation stage, a programmer creates Java source-code files using a text editor. A text editor is different from a word processor, although a word processor can be used to create Java source-code files. If you use a word processor to create a source-code file you must remember to save the file in plain text format. (If you use Microsoft Word, make sure it does not append the .txt file extension to your source file. The java compiler will not be able to compile the file if it has a .txt file extension.)
Java source code can consist of UNICODE characters. A UNICODE character is 16 bits long thus giving it the capability to display a large variety of language characters and symbols such as Korean, Chinese, or Japanese. However, since most text editors can only process ASCII characters, which are 8-bits long, you can represent UNICODE characters in ASCII using escape sequences. To include a UNICODE character using an escape sequence you must consult a UNICODE table to get the encoding for the character you wish to use. For more information about UNICODE you can visit [ www.unicode.org/unicode/standard/standard.html ].
Java source-code files must be saved with a .java file extension. The name of the file must match the class name of the public top-level class defined in the file. (Note: There can be many classes defined within one source file, but only one public top-level class. A top-level class is simply a class that is not nested within another class. In the previous chapter, however, I recommended against placing multiple classes in one source file.)
The second stage of the Java project creation process is source-file compilation. The Java source-code files created in the previous stage must be transformed into byte code using the javac compiler tool. This results in one or more class files being created for each source file. A Java class file has a .class file extension. (Note: If a source code file contains multiple class definitions and/or nested classes, then compilation will result in multiple classes, one for the top-level class and one for each nested class contained within a top-level class.)
A source-code file that contains errors will not compile. In this case, the javac compiler tool will print a series of error messages to the screen. The number of errors in your code determines the number of error messages printed to the screen. If your source file contains errors and does not compile, you must return to the first stage and edit the file to correct the bugs. Note here that the compiler will only catch language syntax and semantic errors along with checked exceptions. (Exceptions are covered in chapter 15.) It will not catch errors in programming logic or fix bad algorithms.
When fixing compiler errors, remember the advice offered in chapter 1: fix the first compiler error first, otherwise you will only make matters worse.
After the source files have been created and compiled, you must use the java interpreter to execute the class file containing the main() method. (A class containing a main() method is referred to as an application class.) Any class files the main application class depends upon must be located in the operating system s CLASSPATH. If, when you try to run a Java program, you get an error that says something like class not found... then you most likely have not properly configured your system s CLASSPATH environment variable.
The second and third stages of the project-creation process can be automated to a certain extent by various development tools. The next section talks about integrated development environments (IDEs) and shows you how an IDE can help speed up your development activities.