javac - The Java Compiler

javac compiles Java programs.

SYNOPSIS

javac [ options ] filename.java ...
javac_g [ options ] filename.java ...

DESCRIPTION

The javac command compiles Java source code into Java bytecodes. You then use the Java interpreter - the java command - to interprete the Java bytecodes.

Java source code must be contained in files whose filenames end with the .java extension. For every class defined in the source files passed to javac, the compiler stores the resulting bytecodes in a file named classname.class. The compiler places the resulting .class files in the same directory as the corresponding .java file (unless you specify the -d option).

When you define your own classes you need to specify their location. Use CLASSPATH to do this. CLASSPATH consists of a colon separated list of directories that specifies the path. If the source files passed to javac reference a class not defined in any of the other files passed to javac then javac searches for the referenced class using the class path. For example:

.:/home/avh/classes
Note that the system always appends the location of the system classes onto the end of the class path unless you use the -classpath option to specify a path.

javac_g is a non-optimized version of javac suitable for use with debuggers like jdb.

OPTIONS

-classpath path
Specifies the path javac uses to look up classes. Overrides the default or the CLASSPATH environment variable if it is set. Directories are separated by colons. Thus the general format for path is:
.:<your_path>
For example:
.:/home/avh/classes:/usr/local/java/classes

-d directory
Specifies the root directory of the class hierarchy. Thus doing:
javac -d <my_dir> MyProgram.java
causes the .class files for the classes in the MyProgram.java source file to be saved in the directory my_dir.

-g
Enables generation of debugging tables. Debugging tables contain information about line numbers and local variables - information used by Java debugging tools. By default, only line numbers are generated, unless optimization (-O) is turned on.

-nowarn
Turns off warnings. If used the compiler does not print out any warnings.

-O
Optimizes compiled code by inlining static, final and private methods. Note that your classes may get larger in size.

-verbose
Causes the compiler and linker to print out messages about what source files are being compiled and what class files are being loaded.

ENVIRONMENT VARIABLES

CLASSPATH
Used to provide the system a path to user-defined classes. Directories are separated by colons, for example,
.:/home/avh/classes:/usr/local/java/classes

SEE ALSO

java, jdb, javah, javap, javadoc,