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.

Get Java Garage 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.