Setting your path to javac and java on PCs

Installation should be straightforward. After installing the JDK, you will want to set up your "path" so that you can simply type javac at the command line to compile. To do this, click the Start Menu and go through the following steps:


 - Control Panel
 - System
 - "Advanced" Tab
 - "Environment Variables" button at bottom
 - Under "System variables," scroll to
 - "Path" and select it
 - click "Edit"
 - a one-line textbox will appear
 - go to the right-hand end and paste the following:

;C:\Program Files\Java\jdk1.5.0_11\bin

 Then enter and click on OK a couple of times to finish.
The semicolon is the windows path separator. That's why it's at the start. After the semicolon is the path to the java compiler (javac) as well as some other tools.

To check that it's working, open a cmd window and type javac -version. You should see javac 1.5.0_11 and then lots of additional lines.

OK, but the command java to actually run the programs isn't working!

This may or may not be happening to you (it depends on earlier interactions of your computer with Java, some of which you might not have realized because it gets used behind the scenes in lots of web-browsing situations).

However, if javac, the compiler, is working, but java is not working (be sure you're typing java CLASSNAME without the .class extension!), then it's almost certainly the so-called "classpath". The classpath is where Java looks for the classes whose main method it will run. You need to have the current directory in your classpath, and this is done by setting the CLASSPATH environment variable. Here's what to do (almost identical to augmenting the Path environment variable, above:


 - Control Panel
 - System
 - "Advanced" Tab
 - "Environment Variables" button at bottom
 - Under "System variables," scroll to
 - "CLASSPATH" and select it IF PRESENT
 - click "Edit"
 - a one-line textbox will appear
 - go to the right-hand end and paste the following:

;.

 Then enter and click on OK a couple of times to finish.

 - if CLASSPATH was NOT PRESENT
 - click "New" (in the lower, "System variables" part of the window)
 - name the new variable CLASSPATH
 - enter the value

.

  Then click on OK a couple of times to finish.
You'll have to start a new command-line window to have the changes take effect. Within a command-line window, you can view the values of all the environment variables with the set command. (You can change them with the same command - type help set for more.)