# javac - The Java Compiler

> The JavaTM CompilerTM `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 interpret the Java bytecodes.

Java source code must be contained in files whose file names end with the `.java` extension. The file name must be constructed from the class name, as in classname`.java`, if the class is public or is referenced from another source file.

For every class defined in each source file compiled by `javac`, the compiler stores the resulting bytecodes in a class file with a name of the form classname`.class`. Unless you specify the `-d` option, the compiler places each class file in the same directory as the corresponding source file.

When the compiler must refer to your own classes, you must specify their location. Use the `-classpath` option or `CLASSPATH` environment variable to do this. The class path is a sequence of directories (or zip files) which `javac` searches for classes that are not already defined in any of the files specified directly as command arguments. The compiler looks in the class path for both a source file and a class file, recompiling the source (and regenerating the class file) if it is newer.

## 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 on Solaris systems and by semicolons on Window 95/NT systems. It is often useful for the directory containing the source files to be on the class path. You should always include the system classes at the end of the path. For example:

  `javac -classpath .:/home/avh/classes:/usr/local/java/classes ...`

`-d` directory
  Specifies the root directory of the class file hierarchy. For example, typing:

  `javac -d /home/avh/classes MyProgram.java`

  causes the class files for the classes in the `MyProgram.java` source file to be saved in the directory `/home/avh/classes/demos/awt`, assuming that the classes are defined in the package `demos/awt`.

  The `-d` and `-classpath` options have independent effects. The compiler reads only from the class path, and writes only to the destination directory. It is often useful for the destination directory to be on the class path. If the `-d` option is not specified, the source files should be stored in a directory hierarchy that reflects the package structure, so that the resulting class files can be easily located.

`-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. 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.

`-depend`
  Makes the compiler consider recompiling class files that are referenced from other class files. (Normally, it only recompiles missing or out-of-date class files that are referred to from source code.)

`-J`javaoption
  Passes the string javaoption as a single argument to the Java interpreter, which runs the compiler. The argument should not contain spaces. Multiple argument words must all begin with the prefix `-J`, which is stripped. This is useful for adjusting the compiler's execution environment or memory usage.

## Environment Variables

CLASSPATH
  Provides the system a path to user-defined classes. Directories are separated by colons on Solaris systems and by semicolons on Windows 95/NT systems. For example:

  `.:/home/avh/classes:/usr/local/java/classes`