Changing the PAth

The PATH system variable is a list of directories where valid commands hang out. When you type a command at the command prompt, all the directories in the PATH variable are checked to see if they contain the command you typed. We want to add the directory where javac.exe and java.exe hang out to the PATH variable. This way, when we type javac at the command prompt, it will know where to find javac.exe.

  1. First, you need to find out where javac.exe and java.exe are. Either do a search, or browse your C:\Program Files for it. Traditionally, they can be found in C:\Program Files\Java\jdk1.6.0_3\bin. Once you find this folder, write down the location.
  2. Right click on the my computer icon and select properties.
  3. In the box that opens, click the "Advanced" tab.
  4. At the bottom left of the tab, you should see a button labeled Environment Variables.
  5. In the box that opens, look for the variable called path or PATH in the system variables section.
  6. highlight this variable and select edit.
  7. You should get a box that lists the variable name and the current value of the variable. It may say something like this.... C:\WINDOWS\System32;C:\WINDOWS Your is likely to have more than just this. The ; here is used to seperate the different directories.
  8. What you want to do is add the directory discovered in Step 1 above to the path. So go to the end of the Variable Value box and add that directory. So, assuming the traditional location, you would add... ;C:\Program Files\Java\jdk1.6.0_3\bin Notice the ; in front of the C. This is how the path variable seperates out the directories. So, given the example in Step 7, your new Variable Value would be.... C:\WINDOWS\System32;C:\WINDOWS;C:\Program Files\Java\jdk1.6.0_3\bin

    Again, you are likely to have more directories in your path.

    Paulo would like to remind you to make certain you spell everything perfectly and that you pay attention to which letters are upper case vs. which letters are lower case.

  9. 8) You should now be ready to compile and execute java programs!!!!! Go ahead and test this now. If when you execute, you get the error java.lang.noClassDefFound ( or something similar ), then do the following....

Moon/Casey Fix

The above error occurs because there is a variable similar to PATH called CLASSPATH. This lists the directories where javac can look for .class files. We will tell java that the current directory ( the . ) is also a valid place to look for .class files.

  1. Right click on the my computer icon and select properties.
  2. In the box that opens, click the "Advanced" tab.
  3. At the bottom left of the tab, you should see a button labeled Environment Variables.
  4. In the box that opens, look for the variable called CLASSPATH in the system variables section. The classpath is a list of directories where java looks for .class files.
  5. highlight this variable and select edit.
  6. You should get a box that lists the variable name and the current value of the variable. To the back end of the current value, add ;.