JAVAC(1) JDK Commands JAVAC(1) (NAME) javac - ( ) (SYNOPSIS) javac [] [--] . -- ( Shape.java) ( geometry.MyShape). (DESCRIPTION) javac (JVM) . javac (annotations) . .java . .class . . Shape Shape.java Shape.class . javac : o . o @filename . javac . . javac . javac . javac (interface) (extend) (implement) . javac . javac . javac . "path" . javac . -d . javac : o JDK. o . o . o javadoc (/** ... */). o . o . javac (API) . (OPTIONS) javac . . javac . (-) (:) . (--) (=) . : -Aname="J. Duke" -proc:only -d myDirectory --module-version 3 --module-version=3 path ( ; : ). JAR JMOD . (Standard Options) @filename . javac javac ( -J) . javac . . -Akey[=value] . javac . key (.) . --add-modules module,module ALL-MODULE-PATH module . --boot-class-path path -bootclasspath path bootstrap (override) . : JDK 9 . --release -source -target . JDK 9 --system . --class-path path -classpath path -cp path . CLASSPATH . o --class-path -classpath -cp CLASSPATH ( ) . o --source-path -sourcepath . o -processorpath . -d directory ( ) . javac ( ) . . -d javac . . . : . --class-path . -deprecation (override) (deprecated) . -deprecation javac . -deprecation -Xlint:deprecation . --enable-preview . lint preview . -source --release . -encoding encoding EUC-JP UTF-8. -encoding . -endorseddirs directories (endorsed standards) . : JDK 9 . --release -source -target . -extdirs directories . directories (; : ) . JAR . JAR . (Extension Mechanism) . [ ] . : JDK 9 . --release -source -target . -g () . . -g:[lines, vars, source] . : lines . vars . source . -g:none . -h directory (native header files) . (native) java.lang.annotation.Native . ( ) . . --help -help -? . --help-extra -X . --help-lint -Xlint . -implicit:[none, class] (implicit) : o -implicit:class --- . o -implicit:none --- . . . -implicit . . -Joption option option java . -J-Xms48m . : CLASSPATH -classpath -bootclasspath -extdirs javac . . -J . --limit-modules module,module* . --module module-name (,module-name)* -m module-name (,module-name)* . --module-path path -p path . --module-source-path module-source-path . . --module-version version . -nowarn . -parameters (reflection) . java.lang.reflect.Executable.getParameters API . -proc:[none, only, full] . o -proc:none . o -proc:only . o -proc:full . . -processor class1[,class2,class3...] . . --processor-module-path path . --processor-path path -processorpath path . . -profile profile API . . : JDK 9 . --release -source -target . --release release Java SE . API Java SE JDK . release Java SE . API Java SE java.* javax.* org.* Java SE (export) API JDK com.* jdk.* JDK javax.* Java SE . API Java SE JDK . : --release --source/-source --target/-target . : --release --add-exports Java SE JDK . -s directory . ( ) . . . . --source release -source release Java SE . release Java SE . Java SE . --source-path path -sourcepath path . . : . . --system jdk | none . --target release -target release class Java SE . release Java SE . : (target) (source) . ( --source .) --upgrade-module-path path . -verbose . . --version -version . -Werror lint lint . -Werror:[-]key(,[-]key)* lint . all none (-) . . ( -Xlint). lint -Xlint . (Extra Options) --add-exports module/package=other-module(,other-module)* ALL-UNNAMED other-module . --add-reads module=other-module(,other-module)* . --default-module-for-created-files module-name (fallback) . --disable-line-doc-comments /// . -Djava.endorsed.dirs=dirs . : JDK 9 . --release -source -target . -Djava.ext.dirs=dirs . : JDK 9 . --release -source -target . --patch-module module=path JAR . -Xbootclasspath:path bootstrap . : JDK 9 . --release -source -target . -Xbootclasspath/a:path bootstrap . : JDK 9 . --release -source -target . -Xbootclasspath/p:path bootstrap . : JDK 9 . --release -source -target . -Xdiags:[compact, verbose] () . -Xdoclint . -Xdoclint:(all|none|[-]group)[/access] . group : accessibility html missing reference syntax. access -Xdoclint . ( ): public protected package private. access private . doclint: group all @SuppressWarnings . DocLint javadoc . -Xdoclint javac . ( ) protected ( protected public) : -Xdoclint:all/protected HTML package ( package protected public) : -Xdoclint:all,-html/package -Xdoclint/package:[-]packages(,[-]package)* . package .* . package (-) . DocLint javadoc . -Xlint . . -Xlint:[-]key(,[-]key)* / . all none (-) . key : o all: . o auxiliaryclass: . o cast: (cast) . o classfile: . o dangling-doc-comments: . o deprecation: . o dep-ann: javadoc @Deprecated . o divzero: 0 . o empty: if . o exports: . o fallthrough: (fall- through) switch . o finally: finally . o identity: (value-based) (identity) . o incubating: / (incubating) . o lossy-conversions: . o missing-explicit-ctor: (public) (protected) . o module: . o opens: (opens) . o options: . o output-file-clash: . . o overloads: (overload) . o overrides: (override) . o path: . o preview: . o processing: . o rawtypes: (raw types) . o removal: API . o restricted: . o requires-automatic: requires . o requires-transitive-automatic: requires transitive . o serial: (serializable) (serial version ID) . . o static: (static) (instance) . o strictfp: strictfp . o synchronization: . identity . identity . o text-blocks: . o this-escape: this . o try: try ( try-with-resources) . o unchecked: (unchecked) . o varargs: (varargs) . o none: . all none @SuppressWarnings . -Xlint . -Xmaxerrs number . -Xmaxwarns number . -Xpkginfo:[always, legacy, nonempty] javac package-info.class package-info.java : always package-info.java package-info.class . Ant .java .class . legacy package-info.class package-info.java . package-info.java package-info.class . : package-info.java RetentionPolicy.SOURCE package-info.class . nonempty package-info.class package-info.java RetentionPolicy.CLASS RetentionPolicy.RUNTIME . -Xplugin:name args . args name args . API API jdk.compiler/com.sun.source.util.Plugin . -Xprefer:[source, newer] . . o -Xprefer:newer: (). o -Xprefer:source : . SOURCE -Xprefer:source . -Xprint . . . -XprintProcessorInfo . -XprintRounds . -Xstdout filename . System.err . (ENVIRONMENT VARIABLES) CLASSPATH --class-path CLASSPATH . --class-path . JDK_JAVAC_OPTIONS JDK_JAVAC_OPTIONS ( ) (\n \t \r \f) javac . javac . JDK_JAVAC_OPTIONS . (') (") . . . @files . @files (wildcard) . : export JDK_JAVAC_OPTIONS='@"C:\white spaces\argfile"' export JDK_JAVAC_OPTIONS='"@C:\white spaces\argfile"' export JDK_JAVAC_OPTIONS='@C:\"white spaces"\argfile' (COMMAND-LINE ARGUMENT FILES) . . . . (*) ( *.java). (@) . -J . javac (@) . javac (@) . javac @filename (Single Argument File) argfile javac : javac @argfile ( ) . (Two Argument Files) : javac . . options : : -d classes -g -sourcepath /java/pubs/ws/1.3/src/share/classes : -d classes -g -sourcepath C:\java\pubs\ws\1.3\src\share\classes sources : MyClass1.java MyClass2.java MyClass3.java javac : javac @options @sources (Argument Files with Paths) ( path1 path2): javac @path1/options @path2/sources (ARRANGEMENT OF SOURCE CODE) . javac . . (Arrangement of Source Code for a Package) . : o p p . o p.q -- q p -- q p . p.q p\q p/q . o p.q.r p\q\r ( ) p/q/r ( ) . .java . : o X p X.java p . o Y p.q Y.java q p . o Z p.q.r Z.java r p\q ( ) p/q ( ) . javac . (Arrangement of Source Code for a Module) . .java module-info.java : 1. 2. ( ) 3. ( ). module-info.java . module-info.java ( ) . (IDE) . : o a.b.c a.b.c . o module-info.java a.b.c . o p.q.r a.b.c p\q\r ( ) p/q/r ( ) . javac . : o a.b.c a.b.c . o a.b.c src\main\java ( ) src/main/java ( ). (CONFIGURING A COMPILATION) javac . . (Source Files) o . . . --module -m . (Output Directory) o -d . . . (Precompiled Code) . . . o --class-path . . : -classpath -cp. o --module-path . . : -p. . : . (Additional Source Files) . . : . o --source-path javac . . : -sourcepath. o --module-source-path javac . . . -implicit . : . (Example of Compiling Multiple Source Files) Aloha.java GutenTag.java Hello.java Hi.java greetings . : % javac greetings/*.java % ls greetings Aloha.class GutenTag.class Hello.class Hi.class Aloha.java GutenTag.java Hello.java Hi.java : C:\>javac greetings\*.java C:\>dir greetings Aloha.class GutenTag.class Hello.class Hi.class Aloha.java GutenTag.java Hello.java Hi.java (Example of Specifying a User Class Path) : : pwd /examples javac greetings/Hi.java : C:\>cd \examples C:\>javac greetings\Hi.java greetings.Hi greetings . . examples CLASSPATH . -classpath . : javac -classpath /examples /examples/greetings/Hi.java : C:\>javac -classpath \examples \examples\greetings\Hi.java greetings.Hi . : javac -classpath /examples:/lib/Banners.jar \ /examples/greetings/Hi.java : C:\>javac -classpath \examples;\lib\Banners.jar ^ \examples\greetings\Hi.java greetings greetings greetings . : java -classpath /examples:/lib/Banners.jar greetings.Hi : C:\>java -classpath \examples;\lib\Banners.jar greetings.Hi (CONFIGURING THE MODULE SYSTEM) --add-modules . API . --limit-modules . . --add-exports . API . --add-reads . API . --patch-module . [ ] . (SEARCHING FOR MODULE, PACKAGE AND TYPE DECLARATIONS) . javac . . java.awt.Window Window : java.awt.Container java.awt.Component java.lang.Object. . . -Xprefer . javac . -implicit . . -implicit . ( ) -implicit . javac . (Searching Package Oriented Paths) javac . () . . . . . (Searching Module Oriented Paths) javac (lazy) : o ( --module-source-path ) o ( --upgrade-module-path ) o ( --system ) o ( --module-path ) () . javac . JAR. javac . (Searching for the Declaration of a Module) module-info.class . module-info.class module-info.java . (Searching for the Declaration of a Type When the Reference is not in a Module) javac : o ( ) ( .) o . ( .) o / : o javac . o javac . o . / . . -Xprefer . (Searching for the Declaration of a Type When the Reference is in a Module) javac . javac . javac . javac . javac . javac : o . o . (DIRECTORY HIERARCHIES) javac ( JAR) . : . javac javac . javac "path" --source-path --class-path. module --module-path . . JAR Class-Path () JAR JAR . JAR . JAR (JAR File Specification) . (Package Hierarchy) .java .class . com.example.MyClass com/example/MyClass.java . (Module Hierarchy) . com.example.MyClass my.library my.library/com/example/MyClass.class . javac ( ) . (Module Source Hierarchy) . . com.example.MyClass my.library my.library/src/main/java/com/example/MyClass.java . (THE MODULE SOURCE PATH OPTION) --module-source-path : . . --module-source-path : o . o . . (Module-specific form) . : o --module-source-path module-name=file-path (path-separator file-path)* ; : . . : --patch-module . (Module-pattern form) . o --module-source-path pattern : o (; : ) . o : string1{alt1 ( ,alt2 )* } string2 "" : string1 alt1 string2 string1 alt2 string2 ... . . o (*) . . M M . : . * (wildcard) . (PATCHING MODULES) javac --patch-module . JVM . : o --patch-module module-name=file-path (path-separator file-path )* ; : . . . . --module-source-path . (ANNOTATION PROCESSING) javac . (API) javax.annotation.processing javax.lang.model . (How Annotation Processing Works) -processor --processor-path --processor-module-path -proc:full -proc:only . -proc:none . . -processorpath . . META-INF/services/javax.annotation.processing.Processor . . -processor . . . (claim) . . : . . . . -proc:only . . --default-module-for-created-files . (Compilation Environment and Runtime Environment) javac javac . javac --class-path --module-path javac javac . . () . . ( --processor-path .) . ( --processor-module-path .) . : 1. javac -J . 2. API javac API . (COMPILING FOR EARLIER RELEASES OF THE PLATFORM) javac --release --source/-source --target/-target . . o JDK 8 . : o --module-source-path --upgrade-module-path --system --module-path --add-modules --add-exports --add-opens --add-reads --limit-modules --patch-module --source/-source --target/-target boot class path . o JDK 9 bootstrap . : o -Xbootclasspath/p: -Xbootclasspath -Xbootclasspath/a: -endorseddirs -Djava.endorsed.dirs -extdirs -Djava.ext.dirs -profile --source/-source --target/-target --system JDK . --release API . (APIS) javac API : Java Compiler API . ToolProvider API ToolProvider javac ToolProvider.findFirst("javac") . . : API API javax.tools . Legacy API javac API . Java Compiler API ToolProvider API . : com.sun.tools.javac ( com.sun.tools.javac) . -XLINT (EXAMPLES OF USING -XLINT KEYS) cast : String s = (String) "Hello!" classfile . deprecation . : java.util.Date myDate = new java.util.Date(); int currentDay = myDate.getDay(); java.util.Date.getDay JDK 1.1 . dep-ann Javadoc @deprecated @Deprecated : /** * @deprecated As of Java SE 7, replaced by {@link #newMethod()} */ public static void deprecatedMethod() { } public static void newMethod() { } divzero 0 : int divideByZero = 42 / 0; empty if : class E { void m() { if (true) ; } } fallthrough switch (fall-through) . switch break . case 1 switch break : switch (x) { case 1: System.out.println("1"); // No break statement here. case 2: System.out.println("2"); } -Xlint:fallthrough case . finally finally : public static int m() { try { throw new NullPointerException(); } catch (NullPointerException e) { System.err.println("Caught NullPointerException."); return 1; } finally { return 0; } } finally . int 0 . finally try . catch int . finally . options . . overrides (override) . : public class ClassWithVarargsMethod { void varargsMethod(String... s) { } } public class ClassWithOverridingMethod extends ClassWithVarargsMethod { @Override void varargsMethod(String[] s) { } } : warning: [override] varargsMethod(String[]) in ClassWithOverridingMethod overrides varargsMethod(String...) in ClassWithVarargsMethod; overriding method is missing '...' varargs varargs . ClassWithVarargsMethod.varargsMethod String... s String[] s ClassWithOverridingMethod.varargsMethod . . path ( ) . @SuppressWarnings . : o : javac -Xlint:path -classpath /nonexistentpath Example.java o : javac -Xlint:path -classpath C:\nonexistentpath Example.java processing . . : AnnoProc.java: import java.util.*; import javax.annotation.processing.*; import javax.lang.model.*; import javax.lang.model.element.*; @SupportedAnnotationTypes("NotAnno") public class AnnoProc extends AbstractProcessor { public boolean process(Set elems, RoundEnvironment renv){ return true; } public SourceVersion getSupportedSourceVersion() { return SourceVersion.latest(); } } AnnosWithoutProcessors.java: @interface Anno { } @Anno class AnnosWithoutProcessors { } AnnoProc AnnosWithoutProcessors.java : javac AnnoProc.java javac -cp . -Xlint:processing -processor AnnoProc -proc:only AnnosWithoutProcessors.java AnnosWithoutProcessors.java : warning: [processing] No processor claimed any of these annotations: Anno AnnosWithoutProcessors Anno NotAnno . rawtypes (raw types) . rawtypes : void countElements(List l) { ... } rawtypes : void countElements(List l) { ... } List . List . List . List (?) countElements List . serial serialVersionUID . : public class PersistentTime implements Serializable { private Date time; public PersistentTime() { time = Calendar.getInstance().getTime(); } public Date getTime() { return time; } } : warning: [serial] serializable class PersistentTime has no definition of serialVersionUID serialVersionUID serialVersionUID . serialVersionUID . InvalidClassExceptions (deserialization) . serialVersionUID serialVersionUID . static (static) : class XLintStatic { static void m1() { } void m2() { this.m1(); } } : warning: [static] static method should be qualified by type name, XLintStatic, instead of by an expression static m1 : XLintStatic.m1(); static m1 . this-escape this . : public class MyClass { public MyClass() { System.out.println(this.hashCode()); } } : MyClass.java:3: warning: [this-escape] possible 'this' escape before subclass is fully initialized System.out.println(this.hashCode()); ^ 'this' . . MyClass hashCode() . ( ) . final . try try try-with-resources . ac try : try ( AutoCloseable ac = getResource() ) { // do nothing} unchecked : List l = new ArrayList(); List ls = l; // unchecked warning (type erasure) ArrayList List ArrayList List . ls List . List l ls (unchecked) . JVM l List . l List . (heap pollution) . List l List List ls (List) . . Java SE (generics) . List List List . l List ls . varargs (varargs) (non-reifiable) : public class ArrayBuilder { public static void addToList (List listArg, T... elements) { for (T x : elements) { listArg.add(x); } } } . ArrayBuilder.addToList : warning: [varargs] Possible heap pollution from parameterized vararg type T varargs varargs . . ArrayBuilder.addToList T... T[] . varargs Object[] . . JDK 26.0.2.1 2026 JAVAC(1)