< Zurück | Inhalt | Weiter >

5.3.2 javac Options

The Java compiler has many command-line options that modify its behavior. We will go over the most important ones here. This is not a complete reference! See the Sun SDK Documentation for complete reference information.

-classpath

Sets the classpath. This overrides the CLASSPATH environment variable, if one is specified.


-d

This switch is followed by a directory name. Compiled classes are placed in that directory. Normally, compiled classes are placed in the same directory as the source code.


-deprecation

This causes every use or reference to a deprecated class or method to be displayed on compilation.2


-g

Put full debugging information in the compiled class files. See also -g:

(the next entry in this list).


-g:keyword_list

This switch gives you fine-grained control over the amount of debug infor- mation included in compiled class files. The argument after the colon may be either none, in which case no debug information is included, or a comma-separated list with any combination of source, to include source file debugging information, lines, to include line number information, or vars, to include information about local variable names. The default, if no -g flag of any kind is specified, is to include source file and line number information only.

-nowarn

Disables warning messages.

-verbose

Causes the compiler to output information about each class encountered during compilation. This can be helpful when trying to resolve problems with missing class definitions.

There are also a number of switches that relate to cross-compiling as well as UNIX-specific options, but these are not commonly used. Refer to the Sun Java SDK Tools documentation if you need details on these options.


image

2. In Java, it is rare for APIs to break support for existing code. Rather than remove old meth- ods, it is more common to deprecate them. This is done by putting a @deprecated tag in a Javadoc comment on the class or method. The Java compiler will issue a warning (if the

-deprecated switch is on) whenever a deprecated class or method is used. In general, depre- cation is a warning that the class or method will be removed in a future version of the code or library. It is interesting to note that the javac compiler records that a method or class is deprecated in the binary. Thus the compiler produces different output based on the contents of a comment. As we have written simple compilers and interpreters, this creeps us out. We have always wondered why deprecated has not become a Java language keyword.

image

5.4 The Java Runtime Engine 121

5.4 THE JAVA RUNTIME ENGINE

You can download and install just the software required to run Java applications without the development tools. This is known as the Java 2 Runtime Edition.