O'Reilly logo

Java Pocket Guide by Patricia Liguori, Robert Liguori

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Command-Line Tools

A JDK provides several command-line tools that aid in software development. Commonly used tools include the compiler, launcher/interpreter, archiver, and documenter. Find a complete list of tools at http://java.sun.com/javase/6/docs/technotes/tools/.

Java Compiler

The Java compiler translates Java source files into Java bytecode. The compiler creates a bytecode file with the same name as the source file but with the .class extension. Following is a list of commonly used compiler options.

javac [-options] [source files]

This is the usage to compile Java source files.

javac HelloWorld.java

This basic usage compiles the program to produce HelloWorld.class.

javac –cp /dir/Classes/ HelloWorld.java

The –cp and –classpath options are equivalent and identify classpath directories to utilize at compile time.

javac –d /opt/hwapp/classes HelloWorld.java

The –d option places generated class files into a preexisting specified directory. If there is a package definition, the path will be included (i.e., /opt/hwapp/src/com/oreilly/ utils/).

javac –s /opt/hwapp/src HelloWorld.java

The –s option places generated source files into a preexisting specified directory. If there is a package definition, the path will be further expanded (i.e., /opt/hwapp/ src/com/oreilly/utils/).

javac –source 1.4 HelloWorld.java

The –source option provides source compatibility with the given release, allowing unsupported keywords to be used as identifiers.

javac –Xlint:unchecked

The –X[lint] option enables ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required