Preliminaries
The paragraphs below assume that you have already downloaded the JDK from Sun's website (see the course web-site for a link)
What is the PATH variable
In order for you to run a program, the computer needs to know the location of that program. By a program, we most often mean the executable file corresponding to that program.
The PATH variable contains a list of paths corresponding to programs on your machine (for Windows they are separated by ;). To run and compile Java programs, you need to be able to use two executable files: java and javac. They are usually located in the bin directory of your Java installation directory. The bin directory needs to be appended to your path, so that you can run the executables regardless of what your current directory is.
What is the CLASSPATH variable
So now you have access to java and javac, but you are facing an orthogonal question. How does java know what class ArrayList is, or any other class for that matter. Just like the PATH points to the executables, the CLASSPATH points to the directories where the classes are contained. At a very minimum, you need to have 2 directories in your classpath: the lib directory of the Java installation and the . (this is a period; it represents the current working directory). Since the classpath is read with a precedence from left to right, the . should always be the first thing in the classpath. This allows you to re-define built-in classes, so that they would be found in your local directory first.
You will likely learn more about the classpath as we talk about packages
Setup On Windows 2000 and XP
Close any command prompt windows you have open (if you're not sure what this means close all programs currently running, except the browser with these instructions, of course).
Right-click the My Computer icon on your desktop and select Properties. Select the Advanced tab. Click the Environment Variables... button. Under "System variables," find the PATH variable and add this to the end of it (this assumes that java is installed in C:\j2sdk1.4.0_01 :make sure you actually put the directory of *your* installation):
;C:\j2sdk1.4.0_01\bin
Then find the CLASSPATH variable.
- If it doesn't exist (and it probably won't), click the New... button, specifying CLASSPATH as its name, and the following value:
.;C:\j2sdk1.4.0_01\lib
-
If it does exist make sure that the value is correct and that the . is the first thing in it.
You may need to restart your system (usually not the case), or at least start up a new Command Prompt window, in order for these changes to take effect.
Running from the Command Line
To open command prompt, click Start, point to All Programs, point to Accessories, and then click Command Prompt.
Now you should be able to type javac and get a message saying that javac needs a parameter and a bunch of options on how to use javac. You are ready to go
Tips from Microsoft on configuring the command prompt
A word on Dr Java, Eclipse and other IDEs
All of the graphical IDEs you might chose to use rely on the PATH and CLASSPATH being setup correctly. It is a good idea that you understand how these variables affect your system, even if you never work from the command prompt