Using the Command Prompt window
In this article, we show you how to compile and run your Java program. We assume that the JDK has been installed in
and your program is stored in a file AreaOfSquare.java in the folder C:\MyJava.
We will run our programs using the “Command Prompt" window. This is also called the MS-DOS window.
Open the window by clicking on Start > All Programs > Accessories > Command Prompt
At the command prompt >, type
The window should now look as follows (your first lines may be slightly different):
This changes the directory to the folder containing your program, AreaOfSquare.java.
To compile the program, we would like to type
where javac.exe is the file containing the compiler.
However, if we did this, we would get a message to the effect that javac is unknown.
The file javac.exe is found in the bin folder of the JDK.
C:\Program Files\java\jdk1.6.0_07\bin is called the “path" to the compiler. We must tell Windows where to find the compiler by setting the Path “environment variable."