Skip to content

Latest commit

 

History

History
 
 

javac

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

README.md

javac

Alternatives

ECJ

Eclipse compiler for Java.

http://stackoverflow.com/questions/3061654/what-is-the-difference-between-javac-and-the-eclipse-compiler

Allows things like:

  • running code in which a part of it does not compile, which may be useful while developing
  • incremental build: building code as soon as you hit save on the IDE very quickly

GCJ

GNU compiler for Java. Obsolete when JDK was made open source.

http://stackoverflow.com/questions/3032727/java-jre-vs-gcj

Basic usage

Compile HelloWorld.java source file into HelloWorld.class bytecode:

javac HelloWorld.java

Then run it with:

java HelloWorld

help

java -help

source

target

-source: specify the version of the source code input.

Can be the current version, or any major prior version.

Example:

javac -source 1.6 A.java

-target: specify the version of the targeted JVM.

bootclasspath

rt.jar

http://stackoverflow.com/questions/7816423/warning-options-bootstrap-class-path-not-set-in-conjunction-with-source-1-5

TODO rt.jar vs other library class files? http://www.ibm.com/developerworks/library/j-5things11/ says: Then your custom implementation needs to be available to the bootstrap ClassLoader, which loads java.lang.Object and all his buddies.

d

Class files output directory.

Example:

javac -d bin A.java

generates bin/A.class.

g

Add full debug information to the class files.

By default, some debug information is already added, namely the line numbers and corresponding source code we see on exception traces.

But other things are not included, in particular local variable information that allows you to do locals on jdb.

HotSpot extensions

All of them are prefixed by -X.

int

comp

Only compile, or only interpret bytecode without compiling. No JIT.

X

lint

Turn on/off compilation warnings.

Compile without having dependencies

Not possible to determine the correct bytecode: http://stackoverflow.com/questions/1537714/disabling-compile-time-dependency-checking-when-compiling-java-classes

Compile Java to ELF

Not sure if there is a convenient method for regular Java programs.

At least https://en.wikipedia.org/wiki/Android_Lollipop from 2014 seems to be doing that.