Java Reference
In-Depth Information
Separating Source Code and Bytecode Files
You might have been wondering why the examples in this chapter separated the source
fi les from the bytecode fi les. In general, when you distribute your code you do not want
the JAR fi les to include your source code. Having the bytecode separate makes it much
easier to create JAR fi les that only contain your bytecode.
You might have also noticed that the source code fi les in \src use the same directory
structure as their package names. This is not a requirement for your .java fi les; they can
be stored in any directory. In most development teams, you will be required to run the
javadoc tool on your source fi les to generate the HTML documentation for your classes
and interfaces. The javadoc tool requires that your source fi le directories match the pack-
age names. The exam does not contain any questions that involve the javadoc tool, but in
the real world you will quickly learn to appreciate the benefi ts of javadoc documentation!
In projects I work on, we put source code in the \src directory, using the package name
subdirectory structure. Bytecode goes in a subdirectory of \build depending on whether
or not the bytecode is in a JAR. JAR fi les appear in the \build\lib directory, and .class
fi les appear in the \build\classes subdirectory that matches the package name structure.
Command-Line Arguments
The java.exe executable starts the JVM, and on the command line you provide the name
of the class that contains the main method. The command-line arguments are passed into
the main method as a single array of String objects. For example, suppose PrintGreetings
is a class that contains main and it is executed with the command line in Figure 1.4.
FIGURE 1.4 This command line starts the JVM and invokes the main method in the
PrintGreetings class.
java com.sybex.demos.PrintGreetings hi goodbye see you later
The JVM
executable
args[0]
args[2]
args[4]
The name of the class
that contains the main
method
args[1]
args[3]
 
Search WWH ::




Custom Search