In this article, we show you how to compile and run your Java program. We assume that the JDK has been installed in
C:\Program Files\java\jdk1.6.0_07
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 cd C:\MyJava
The window should now look as follows (your first lines may be slightly different):

click to enlarge
This changes the directory to the folder containing your program, AreaOfSquare.java.
To compile the program, we would like to type
javac AreaOfSquare.java
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.”