Java 6 in 21 Days (5th Edition): Using the JDK on Windows

The cover of Teach Yourself Java 6 in 21 Days (5th Edition) by Rogers Cadenhead

Home Buy the Book Thanks Other Books

Setting Up the PATH on Windows 95, 98, or Me

If you're using Windows XP, 2000, or NT, skip to the next section.

On a Windows 95, 98, or Me system, the root folder of your Windows system should contain a file called AUTOEXEC.BAT. This file is used by MS-DOS to configure how the operating system and some command-line programs function.

AUTOEXEC.BAT is a text file you can edit with Windows Notepad. Start Notepad and open the file \AUTOEXEC.BAT to begin editing it. (The slash in front of the filename causes Notepad to look for it in the root folder.)

When you open the file, you'll see a series of MS-DOS commands, each on their own line, as shown below.

Editing AUTOEXEC.BAT

The only commands you need to look for are any that begin with PATH or SET CLASSPATH=.

The PATH command is followed by a space and a series of folder names separated by semi-colons.

PATH is used to help MS-DOS find programs when you run them at a command line. In the preceding example, the PATH command highlighted in yellow includes three folders:

  • C:\PROGRA~1\MSOFFICE\OFFICE
  • C:\PROGRA~1\MSBOB
  • C:\jdk1.6\bin

You can see what PATH has been set to by typing the following command at an MS-DOS Prompt:

  • PATH

To set up the Java Development Kit correctly, the folder that contains the Java interpreter must be included in the PATH command in AUTOEXEC.BAT. The interpreter has the filename java.exe. If you installed the JDK in the C:\jdk1.6 folder on your system, java.exe is probably in C:\jdk1.6\bin.

If you can't remember where you installed the JDK, you can look for java.exe by clicking the Start button, choosing Find, and clicking Files or Folders. You may find several copies in different folders. To see which one is correct, open an MS-DOS Prompt window and do the following for each copy of the program:

  • Use the CD command to open a folder that contains java.exe.
  • Run the command java -version in that folder.

When you know the correct folder, create a blank line at the bottom of the AUTOEXEC.BAT file and add the following:

  • PATH rightfoldername;%PATH%

For example, if c:\javajdk\bin is the correct folder, the following line should be added at the bottom of AUTOEXEC.BAT:

  • PATH c:\javajdk\bin;%PATH%

The %PATH% text keeps you from wiping out any other PATH commands in AUTOEXEC.BAT.

After making changes to AUTOEXEC.BAT, save the file and reboot your computer. Once this is done, try the java -version command. If it works, your JDK may be configured correctly. To see if it is, continue to the next page.

Setting Up Path on Windows NT, 2000, or XP

On a Windows 2000, NT, or XP system, you must set up at least one environment variable to use the JDK. These variables are part of the Windows Control Panel.

To change your variables:

Right-click the My Computer icon on the desktop or the Start menu and choose Properties. The System Properties dialog box opens.

Click the Advanced tab to bring it to the front.

Click the Environment Variables button. The Environment Variables dialog opens, as shown below.

Editing Environment Variables

The System variables section contains variables that apply to all users on the computer. Scroll to the Path item, select it with the mouse and click the Edit button. The Edit System Variable dialog opens, as shown below.

Editing System Variables

The Path variable contains a series of folder names separated by semi-colons. This variable is used to help Windows find programs when you run them at a command line.

Click your mouse in the Variable value text field and scroll to the end of the text.

To set up the Java Development Kit correctly, the folder that contains the Java interpreter must be included in the Path variable. The interpreter has the filename java.exe. If you installed the JDK in the C:\jdk1.6 folder on your system, java.exe is probably in C:\jdk1.6\bin.

If you can't remember where you installed the JDK, you can look for java.exe by clicking the Start button, choosing Find, and clicking Files or Folders or Start, Search. You may find several copies in different folders. To see which one is correct, open an MS-DOS Prompt window and do the following for each copy of the program:

  • Use the CD command to open a folder that contains java.exe.
  • Run the command java -version in that folder.

When you know the correct folder, click your mouse in the Variable Value text field and scroll to the end of the text, then add a semi-colon followed by the folder where java.exe was installed.

For example, if c:\javajdk\bin is the correct folder, the following text should be added at the end of the Variable Value field: ;c:\javajdk\bin

After making this change, click OK to close the Edit System Variable dialog and click OK again to close the Environmental Variables dialog. Once this is done, open a command-line window and try the java -version command. If it works, your JDK may be configured correctly.

To see if it is, continue to the next page.