javac
Java source code compiler
TLDR
Compile a Java file
SYNOPSIS
javac [OPTIONS] SOURCE-FILES
javac [OPTIONS] @ARGFILE
DESCRIPTION
javac compiles Java source files (.java) into bytecode class files (.class) that run on the Java Virtual Machine. It performs syntax and type checking, optimizes code, and generates platform-independent bytecode.
The compiler uses the classpath to locate referenced classes and libraries. For modular projects (Java 9+), the module path specifies module locations. The --release flag ensures compatibility with a specific Java version for both compilation and available APIs.
When compiling many files, use @argfiles to avoid command-line length limits. Each line in the argfile can contain a source file or option.
PARAMETERS
-d DIR
Output directory for compiled class files.-cp, -classpath PATH
Classpath for finding user class files and libraries.--module-path PATH
Module path for finding application modules.-sourcepath PATH
Path for finding source files.--release VERSION
Compile for specific Java SE release.-source VERSION
Source code compatibility version.-target VERSION
Generate class files for specific VM version.-Xlint[:WARNINGS]
Enable warnings (all, deprecation, unchecked, etc.).-g
Include debugging information.-verbose
Output messages about what the compiler is doing.-deprecation
Show description of deprecated API usage.-encoding ENCODING
Source file character encoding.-h DIR
Generate native header files for JNI.@FILE
Read options and filenames from file.
CONFIGURATION
JAVA_HOME
Environment variable pointing to the JDK installation directory.CLASSPATH
Environment variable specifying default class search paths for compilation.
CAVEATS
Source and class files must match Java package structure with directory paths. Circular dependencies between source files require all files to be compiled together. The classpath separator is : on Unix and ; on Windows.
HISTORY
javac has been part of the Java Development Kit since Java 1.0 in 1996. The compiler has evolved significantly, adding generics (Java 5), modules (Java 9), and numerous language features. Modern versions support incremental compilation and annotation processing.
