javac(1) Basic Tools javac(1) (NAME) javac - (SYNOPSIS) javac [ options ] [ sourcefiles ] [ classes] [ @argfiles ] : options (OPTIONS) . sourcefiles ( MyClass.java). classes ( MyPackage.MyClass). @argfiles . -J . (DESCRIPTION) javac . javac (annotations) . javac : o . o . (@) javac . .java .class . MyClass MyClass.java MyClass.class . . MyClass$MyInnerClass.class. (package) . /workspace com.mysoft.mypack.MyClass /workspace/com/mysoft/mypack/MyClass.java . . -d . (OPTIONS) . . -X . o << (Cross-Compilation Options)>> o << (Nonstandard Options)>> (STANDARD OPTIONS) -Akey[=value] . javac . key (.) . -cp path -classpath path ( ) . CLASSPATH (override) . CLASSPATH -cp -classpath . -sourcepath . -processorpath . -Djava.ext.dirs=directories . -Djava.endorsed.dirs=directories (endorsed standards) . -d directory . javac . javac . -d /home/myclasses com.mypackage.MyClass /home/myclasses/com/mypackage/MyClass.class . -d javac . : -d . -deprecation (override) . -deprecation javac . -Xlint:deprecation . -encoding encoding ( EUC-JP UTF-8). -encoding . -endorseddirs directories . -extdirs directories ext . directories (:) . JAR JAR . ( ) . << >> . -g . . -g:none . -g:[keyword list] . : source . lines . vars . -help . -implicit:[class, none] . -implicit:class -implicit:none . . . . << >> . -Joption option (JVM) option . -J-Xms48m . java(1) . : CLASSPATH -classpath -bootclasspath -extdirs javac . . -J . -nowarn . -Xlint:none . -parameters java.lang.reflect.Executable.getParameters API (Reflection) . -proc: [none, only] . -proc:none . -proc:only . -processor class1 [,class2,class3...] . . -processorpath path . . -s dir . javac . . -s /home/mysrc com.mypackage.MyClass /home/mysrc/com/mypackage/MyClass.java . -source release . release : 1.3 (assertions) Java SE 1.3 . 1.4 assertion Java SE 1.4 . 1.5 Java SE 5 . 5 1.5. 1.6 Java SE 6 . 6 1.6. 1.7 Java SE 7 . 7 1.7. 1.8 . Java SE 8 . 8 1.8. -sourcepath sourcepath . Oracle Solaris (:) (;) JAR ZIP . . : . << >> . -verbose . -version . -werror . -X . (CROSS-COMPILATION OPTIONS) javac . javac (cross-compilation) . -bootclasspath -extdirs . -target version . JVM . 1.1 1.2 1.3 1.4 1.5 ( 5) 1.6 ( 6) 1.7 ( 7) 1.8 ( 8). -target -source : o -source -target 1.8 . o -source 1.2 -target 1.4 . o -source 1.3 -target 1.4 . o -source 1.5 -target 1.8 . o -source 1.6 -target 1.8 . o -source 1.7 -target 1.8 . o -source -target -source . -bootclasspath bootclasspath . (:) JAR ZIP . (COMPACT PROFILE OPTION) JDK 8 javac (compact profiles) . . . JRE . compact1 compact2 compact3. API . -profile : javac -profile compact1 Hello.java javac API . : cd jdk1.8.0/bin ./javac -profile compact1 Paint.java Paint.java:5: error: Applet is not available in profile 'compact1' import java.applet.Applet; Applet . -profile API Java SE ( Applet ). -bootclasspath rt.jar . -profile . (NONSTANDARD OPTIONS) -Xbootclasspath/p:path . -Xbootclasspath/a:path . -Xbootclasspath/:path . -Xdoclint:[-]group [/access] group : accessibility syntax reference html missing. -Xdoclint javadoc . -Xdoclint javac . access (visibility) . ( ): public protected package private. protected : -Xdoclint:all/protected HTML package : -Xdoclint:all,-html/package -Xdoclint:none . -Xdoclint:all[/access] . -Xlint . . -Xlint:all . . -Xlint:none . -Xlint:name . << -XLINT>> . -Xlint:-name . << -XLINT>> . -Xmaxerrs number . -Xmaxwarns number . -Xstdout filename . System.err . -Xprefer:[newer,source] ( << >> ). -Xprefer:newer (). -Xprefer:source . -Xpkginfo:[always,legacy,nonempty] javac package-info.class package-info.java . : always package- info.java package-info.class . legacy package- info.class package-info.java . . : package-info.java RetentionPolicy.SOURCE . nonempty package- info.class RetentionPolicy.CLASS RetentionPolicy.RUNTIME . -Xprint . . . -XprintProcessorInfo . -XprintRounds . -XLINT (ENABLE OR DISABLE WARNINGS WITH THE -XLINT OPTION) name -Xlint:name name . -Xlint:-name . cast (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) . 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 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 : javac -Xlint:path -classpath /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 (unbounded wildcard) . List . List (?) countElements List . serial serialVersionUID (serializable) : 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) . 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 m1 : XLintStatic.m1(); static m1 . try try try-with-resources . ac try : try ( AutoCloseable ac = getResource() ) { // do nothing} unchecked (unchecked conversion) : List l = new ArrayList(); List ls = l; // unchecked warning (type erasure) ArrayList List ArrayList List . ls List . List l ls unchecked . JVM l List . (heap pollution) . l List List ls List . Java SE . List . 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[] Object[] . (COMMAND-LINE ARGUMENT FILES) javac javac ( -J) . javac . javac . . . . (*) ( *.java). (@) . -J . javac (@) . javac (@) . : argfile javac : javac @argfile . : : javac . . options : -d classes -g -sourcepath /java/pubs/ws/1.3/src/share/classes classes : MyClass1.java MyClass2.java MyClass3.java javac : javac @options @classes : ( path1 path2): javac @path1/options @path2/classes (ANNOTATION PROCESSING) javac apt . (API) javax.annotation.processing javax.lang.model . (HOW ANNOTATION PROCESSING WORKS) -proc:none . -processorpath . . META-INF/services/javax.annotation.processing.Processor . . -processor . . . (claim) . . : . . . -proc:only . (IMPLICITLY LOADED SOURCE FILES) ( << >> ). . . -implicit . (SEARCHING FOR TYPES) (type) . (extend) (implement) . . java.applet.Applet java.awt.Panel java.awt.Container java.awt.Component java.lang.Object . . ( ) . CLASSPATH -classpath . -sourcepath . -bootclasspath -extdirs . << >> . . -Xprefer . newer (). source . . . -implicit : none class . . -implicit . -implicit . (PROGRAMMATIC INTERFACE) javac API javax.tools . (EXAMPLE) : JavaCompiler javac = ToolProvider.getSystemJavaCompiler(); (diagnostics) javac . javax.tools.JavaCompiler . (OLD INTERFACE) : API . API Java Compiler . com.sun.tools.javac.Main : public static int compile(String[] args); public static int compile(String[] args, PrintWriter out); args . out . (exit code) javac . : com.sun.tools.javac . (EXAMPLES) : Hello.java greetings . Hello.java greetings.Hello . greetings . -d . Hello.java: package greetings; public class Hello { public static void main(String[] args) { for (int i=0; i < args.length; i++) { System.out.println("Hello " + args[i]); } } } greetings.Hello: javac greetings/Hello.java greetings.Hello: java greetings.Hello World Universe Everyone Hello World Hello Universe Hello Everyone : 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 : : pwd /examples javac greetings/Hi.java greetings.Hi greetings . . examples CLASSPATH . -classpath : javac -classpath /examples /examples/greetings/Hi.java greetings.Hi : javac -classpath /examples:/lib/Banners.jar \ /examples/greetings/Hi.java greetings greetings greetings : java -classpath /examples:/lib/Banners.jar greetings.Hi : javac JVM 1.7 : javac -source 1.7 -target 1.7 -bootclasspath jdk1.7.0/lib/rt.jar \ -extdirs "" OldCode.java -source 1.7 1.7 ( 7) OldCode.java . -target 1.7 JVM 1.7 . -target -source -target . -bootclasspath ( rt.jar) . : javac -source 1.7 OldCode.java warning: [options] bootstrap class path not set in conjunction with -source 1.7 ( 1.7 ) ( Java SE 7) . : javac JVM 1.7 : javac -source 1.7 -target 1.7 -bootclasspath jdk1.7.0/lib/rt.jar \ -extdirs "" OldCode.java -source 1.7 1.7 ( 7) OldCode.java . -target 1.7 JVM 1.7 . -bootclasspath ( rt.jar) : javac -source 1.7 OldCode.java warning: [options] bootstrap class path not set in conjunction with -source 1.7 . . 1.7 . (SEE ALSO) o java(1) o jdb(1) o javadoc(1) o jar(1) o jdb(1) JDK 8 03 March 2015 javac(1)