javac Command

The javac command compiles a program from a command prompt. It reads a Java source program from a text file and creates a compiled Java class file. The basic form of the javac command is

javac filename [options]

For example, to compile a program named HelloWorld.java, use this command:

javac HelloWorld.java

Normally, the javac command compiles only the file that you specify on the command line, but you can coax javac into compiling more than one file at a time by using any of the following techniques:

check.png If the Java file you specify on the command line contains a reference to another Java class that’s defined by a java file in the same folder, the Java compiler automatically compiles that class, too.

check.png You can list more than one filename in the javac command. The following command compiles three files:

javac TestProgram1.java TestProgram2.java TestProgram3.java

check.png You can use a wildcard to compile all the files in a folder, like this:

javac *.java

check.png If you need to compile a lot of files at the same time but don’t want to use a wildcard (perhaps you want to compile a large number ...

Get Java For Dummies Quick Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.