'javac' - Java Compilation Command and Options

This section describes what are the commonly used command line options for the Java compiler - 'javac' tool.

"javac": A command line tool that reads Java source files and compiles them into bytecode class files. "javac" is distributed as part of the JDK package and represented by the \progra~1\java\jdk1.8.0\bin\javac.exe program file. It has the following syntax:

javac [options] [sourcefiles]

where "options" is a list of options and "sourcefiles" is a list of Java source files.

Commonly used options are:

If you run the "javac" command without any options, you will get the quick usage information as shown below:

C:\herong>\progra~1\java\jdk1.8.0\bin\javac

Usage: javac <options> <source files>
where possible options include:
 -g                     Generate all debugging info
 -g:none                Generate no debugging info
 -g:{lines,vars,source} Generate only some debugging info
 -nowarn                Generate no warnings
 -verbose               Output messages about what the compiler is 
                        doing
 -deprecation           Output source locations where deprecated APIs 
                        are used
 -classpath <path>      Specify where to find user class files and 
                        annotation processors
 -cp <path>             Specify where to find user class files and 
                        annotation processors
 -sourcepath <path>     Specify where to find input source files
 -bootclasspath <path>  Override location of bootstrap class files
 -extdirs <dirs>        Override location of installed extensions
 -endorseddirs <dirs>   Override location of endorsed standards path
 -proc:{none,only}      Control whether annotation processing and/or 
                        compilation is done.
 -processor <class1>[,<class2>,<class3>...] Names of the annotation 
                        processors to run; bypasses default discovery 
                        process
 -processorpath <path>  Specify where to find annotation processors
 -parameters            Generate metadata for reflection on method 
                        parameters
 -d <directory>         Specify where to place generated class files
 -s <directory>         Specify where to place generated source files
 -h <directory>         Specify where to place generated native header
                        files
 -implicit:{none,class} Specify whether or not to generate class files
                        for implicitly referenced files
 -encoding <encoding>   Specify character encoding used by source files
 -source <release>      Provide source compatibility with specified 
                        release

 -target <release>      Generate class files for specific VM version
 -profile <profile>     Check that API used is available in the 
                        specified profile
 -version               Version information
 -help                  Print a synopsis of standard options
 -Akey[=value]          Options to pass to annotation processors
 -X                     Print a synopsis of nonstandard options
 -J<flag>               Pass <flag> directly to the runtime system
 -Werror                Terminate compilation if warnings occur
 @<filename>            Read options and filenames from file

Last update: 2015.

Table of Contents

 About This Book

 Java Tools Terminology

 Installing Java 8 on Windows

'javac' - The Java Program Compiler

'javac' - Java Compilation Command and Options

 Compiling Hello.java - My First Java Program

 Option '-classpath' - Specifying Class Path

 Option '-sourcepath' - Specifying Source Path

 Option '-d' - Specifying Output Directory

 Two Types of 'import' Statements

 'import' Statements Processed by 'javac'

 Option "-g" - Controlling Debugging Information

 'java' - The Java Program Launcher

 'jdb' - The Java Debugger

 'jconsole' - Java Monitoring and Management Console

 'jstat' - JVM Statistics Monitoring Tool

 JVM Troubleshooting Tools

 jvisualvm (Java VisualVM) - JVM Visual Tool

 'jar' - The JAR File Tool

 'javap' - The Java Class File Disassembler

 'keytool' - Public Key Certificate Tool

 'native2ascii' - Native-to-ASCII Encoding Converter

 Outdated Tutorials

 References

 PDF Printing Version