javac compiles Java programs.
javac [ options ] filename.java ... javac_g [ options ] filename.java ...
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: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..:/home/avh/classes
javac_g is a non-optimized version of javac suitable for use with debuggers like jdb.
- -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:For example:.:<your_path>.:/home/avh/classes:/usr/local/java/classes
- -d directory
- Specifies the root directory of the class hierarchy. Thus doing:causes the .class files for the classes in the MyProgram.java source file to be saved in the directory my_dir.javac -d <my_dir> MyProgram.java
- 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.
- Turns off warnings. If used the compiler does not print out any warnings.
- Optimizes compiled code by inlining static, final and private methods. Note that your classes may get larger in size.
- Causes the compiler and linker to print out messages about what source files are being compiled and what class files are being loaded.
- 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
java, jdb, javah, javap, javadoc,