Setting the ``path'' variable for using the JDK with Windows

Perhaps you have installed the JDK on your computer, yet when you try to compile a Java program from an MS-DOS command window,
javac MyPackage\MyClass.java
or you try to use javadoc,
javadoc MyPackage
the commands do not work---the computer cannot find javac (or javadoc). Perhaps you have similar difficulties with trying to use java or jar.

The problem is that your computer's ``path'' variable is incorrectly set.

Background

The Windows OS comes with loads of programs, and they are stored in many different folders, e.g, C:\WINNT\system32 and also C:\WINNT\ and also others. When you click on an icon to start a program, the computer code hiding ``inside'' the icon includes a path (the name of the folder) where the program is stored. The Windows OS uses the path to find the program and start it.

Now, when you make an MS-DOS command window, you can start a program by typing text into the window. For example, I can open a command window and start the notepad text editor by typing the word,

notepad
The notepad program lives within the folder, C:\WINNT\system32; so, how did the Windows OS locate notepad?

The answer goes like this: The Windows OS keeps a list of all the folders that hold executable programs (``.exe files''). The list is called the path variable. The path variable for Windows OS might look like this:

PATH=C:\WINNT\system32;C:\WINNT
This path variable lists two folders that hold executable programs. (Note the semicolon.) So, when we type, notepad, in a command window, then Windows OS searches the folders listed in its path variable to find notepad. Eventually, notepad is found and started.

Installing new software on your computer

Say that you install the JDK on your computer. The installation will construct a new folder on your C:\ disk drive, probably named jdk1.1.3 or something quite similar. Inside that folder are executable programs like javac and java. To start these programs from a command window, you must add the folder name to the path variable, say, so that it looks like this:
PATH=C:\WINNT\system32;C:\WINNT;C:\jdk1.1.3\bin
Some JDK installation programs automatically modify the path variable to look like the above, but many do not. If you encounter the problem described at the beginning of this note, then you must manually modify the path variable.

How to modify the path variable

First, try the following:

Now, we wish to add the directory path, C:\jdk1.1.3\bin, to the end of the Window OS's ``path'' variable.

  1. From the START menu, click on Control Panel; when the Control Panel window appears, click on System. (Note: if you do not see an icon for System, then use the link at the upper left of the Control-Panel window to ``Switch to Classic View.'' This will make visible the System icon.
  2. In the System Properties window that appears, click on Advanced. Then, click on Environment Variables. Another window appears: In the list of System Variables, select Path and then press the Edit button. You will see another new window that allows you to alter the value of the Path variable.
  3. At the end of the text for the Path variable, add a semicolon and the directory path to Java (but no spaces!):
    ;C:\jdk1.1.3\bin
    
    Then, press OK.
To check if you are successful at altering the path, open an MS-DOS window, and type path in it. You will see the value of the path variable. It should look something like this:
PATH=C:\WINNT\system32;C:\WINNT;C:\jdk1.1.3\bin
At this point, you are ready to use java, javadoc, jar, etc., from the MS-DOS command window. First try typing javac in the MS-DOS window; a description of how to use javac should print after a few seconds. If a ``not recognized message'' appears instead, then the Path variable is not correctly set, and you should try again.

What if I cannot reset the path variable?

If you cannot complete the above steps, here is a hack that always works: Open an MS-DOS command window, and type this:
set PATH=C:\jdk1.1.3\bin
(or whatever is the exact path to the Java compiler and interpreter). This forces the path variable for this command window only to remember the path to where the Java programs live.