O'Reilly logo

Java Garage by Eben Hewitt

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

Compiling Source Code

To compile Java programs after you have installed the SDK, open a console. In Windows, go to Start > Run and type cmd to get a command prompt.

Note that if you have multiple JDKs on your system, you may need to supply the –source 1.5 flag to the javac command to ensure that your code is compiled correctly.

C:\garage\src>javac -source 1.5
     net\javagarage\demo\MyProgram.java

This compiles the Java source code into a class file in the same directory.

If all goes well during compilation, you get a new command prompt, and nothing else. You are now ready to run your program using the java command.

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