Sams Teach Yourself Java 6 in 21 Days

Using the JDK on a Windows System


When you compile a Java program with the JDK, you type a command such as the following at a command line:

  • javac

If you compile a program successfully, you won't see any output. Try to run the program:

  • java HelloWorld

If programs compile and run OK, the Java Development Kit has been configured successfully. You don't need to make any more changes.

If you see a "class not found" error whenever you try to compile a program, you need to make one more adjustment.

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

Setting Up CLASSPATH on Windows 95, 98, and Me

There's one more line that needs to be edited, or added, to your AUTOXEC.BAT file: The CLASSPATH.

When you run Notepad and open \AUTOEXEC.BAT, you'll see a series of MS-DOS commands like those shown below.


The SET CLASSPATH= command is followed by a series of folder and filenames separated by semi-colons.

CLASSPATH is used to help the Java compiler find the Java class library and other class files that it needs. In the preceding example, the SET CLASSPATH= command highlighted in green includes three things:

  • .
  • c:\jdk1.6\lib$classfile
  • c:\jdk1.6

A CLASSPATH can contain folders (such as c:\jdk1.6 in the preceding example) and files (c:\jdk1.6\lib$classfile). It also can contain a period character ("."), which is another way to refer to the current folder in MS-DOS.

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


If your CLASSPATH includes folders or files that you know are no longer on your computer, you should remove the references to them on the SET CLASSPATH= line in AUTOEXEC.BAT. Make sure to remove any extra semi-colons also.

To set up the Java Development Kit correctly, the file containing the Java class library must be included in the SET CLASSPATH= command. The interpreter has the filename tools.jar. If you installed the JDK in the C:\jdk1.6 folder on your system, tools.jar should be in C:\jdk1.6\lib.

If you can't remember where you installed the JDK, you can look for tools.jar by clicking Start, Find, Files or Folders. If you find several copies, you should be able to find the correct one using this method:

  • Use CD to open the folder that contains the Java interpreter (java.exe)
  • Enter the command CD ..
  • Enter the command CD lib

The lib folder should contain the right copy of tools.jar.

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

  • SET CLASSPATH=%CLASSPATH%;.;rightlocation

For example, if tools.jar file is in the c:\javajdk\lib folder, the following line should be added at the bottom of AUTOEXEC.BAT:

  • SET CLASSPATH=%CLASSPATH%;.;c:\javajdk\lib$classfile

As you might expect, the %CLASSPATH% text keeps you from removing any other CLASSPATH commands in AUTOEXEC.BAT.

After making changes to AUTOEXEC.BAT, save the file and reboot your computer. Once this is done, try to compile one of the sample programs from this Web site.

If you are still having problems running java -version or getting "class not found" errors after completing this tutorial, send e-mail to my JDK setup mailbox.

Setting Up ClassPath on Windows NT, 2000, or XP

On a Windows 2000, NT, or XP system, there's one more environment variable that may need to be edited, or added, in your Control Panel: The ClassPath variable.

To see the variables set up on your computer:


Search terms used to find this page: Java programming, teach yourself, 21 days, how to, learn, Sams, Pearson, Macmillan, Java 6, JDK 6, Java6, JDK1.6, Java 1.6, JDK 1.6, SDK1.6, Java 6 SDK 1.6, SDK 1.6, Java 6 version 1.6, Java 6 SDK, Java SDK, Rogers Cadenhead, Laura Lemay, tutorial, hands-on, source code, code, javac, java, application, appletviewer, help, learning, applet, servlet, servlets, JSP, Swing, GUI, interface, XML, JavaSound, Java2D, JDBC, JavaBeans, object serialization, IO, Tomcat, Apache, Java API for XML Parsing, Java API for XML Processing, XML-RPC, XOM, Web services, regular expressions, regex, java.nio, buffers, channels

Valid HTML 4.01!

Valid CSS!