Owl Sams Teach Yourself Java 2 in 24 Hours

Windows and Windows 95/98 Setup

Be sure to read this entire page. There's a part at the end involving Windows Notepad that can solve some problems you might be having.

Some readers are having trouble getting their first program to compile on Windows systems. If you are getting a "file not found" error or "class not found" error when you compile your first program in Hour 2, this probably indicates that your system is having trouble finding your Java Development Kit.

Windows 95, 98, and 3.1 systems have a file in the root directory called AUTOEXEC.BAT. This file contains information that is used by some DOS-based programs, including the Java Development Kit.

Here's a step-by-step way to make sure that your system is set up to use the Java Development Kit for Java 2.

  1. Find out which directory on your system contains the file javac.exe. You can use the Find Files or Folders... feature to do this in Windows 95, or File Manager's Search | File feature in Windows 3.1. On my system, javac.exe can be found in the directory c:\jdk1.2\bin. Write this directory down -- it is your Java path.
  2. Find out which directory on your system contains the file tools.jar. This directory should be similar to the last one. On my system, it is in the directory c:\jdk1.2\lib. Write this down also -- it is your Java class path. Also, be sure to capitalize toos.jar exactly as it appears when you find the file.
  3. Go to your c:\ directory (your root directory) and make a backup copy of your AUTOEXEC.BAT file. Give it a name such as AUTOEXEC.BAK.
  4. Open up AUTOEXEC.BAT with a text editor such as Notepad.
  5. Look for a line in this file that begins with the text PATH=. If you find it, the line will include a list of directories, as in the following from my system:
    PATH=c:\windows\command;c:\dosutils
  6. If you find a line that begins PATH=, add a semicolon to it and the name of your Java path. On my system, I would add the text ;c:\jdk1.2\bin to the end of the line, so that it would become the following:
    PATH=c:\windows\command;c:\dosutils;c:\jdk1.2\bin
  7. If you don't find a line that begins PATH=, create a new line that begins with the text PATH= and continues with the name of your Java path. On my system, it would look like the following:
    PATH=c:\jdk1.2\bin
  8. Now you're ready to look for a line in AUTOEXEC.BAT that begins with the text SET CLASSPATH=. It will also have a list of directories.
  9. If you find this line, add the name of your Java class path followed by the text \tools.jar. On my system, I would add the text ;c:\jdk1.2\lib\tools.jar, so that it would become the following:
    SET CLASSPATH=c:\vrml\classes;c:\jdk1.2\lib\tools.jar
  10. Also, add the text .; immediately after CLASSPATH=. On my system, it would become the following:
    SET CLASSPATH=.;c:\vrml\classes;c:\jdk1.2\lib\tools.jar
  11. If you don't find a SET CLASSPATH line, create a new one that begins with the text SET CLASSPATH=.; and continues with the name of your Java class path and the text \tools.jar. On my system, it would look like the following:
    SET CLASSPATH=.;c:\jdk1.2\lib\tools.jar
  12. Save the AUTOEXEC.BAT file with these changes, and reboot your computer.

This should take care of the problem for most people. The only thing that might complicate matters is if you previously installed a different Java programming tool on your system. In that case, it is advisable to deinstall all other Java programming tools before installing JDK 2.

Windows Notepad Help

If you're using the Notepad editor to create Java source files, you need to take an extra step to make sure that it saves the files under the correct name.

When you save a file in Notepad, put quote marks around the filename, as in "BigDebt.java". This prevents Notepad from adding the .txt file extension to the name, turning it into BigDebt.java.txt. This problem does not occur under all Windows 95 configurations, but on those where it occurs, you won't be able to compile the program unless you rename it to take out the .txt file extension.

By putting quote marks around the filename as you're saving it in Notepad, you prevent .txt from being added under any Windows 95 or Windows 98 configuration.

If you continue experiencing problems, I encourage you to send me e-mail.