Setting the CLASSPATH

A final detail related to Java programming involves setting the CLASSPATH environment variable to tell the Java interpreter where to find classes.

Recall from a previous section the installation directory structure of Sun's JDK:

                     bin/             binaries (java, javac, etc.)
                     jre/lib/         bootstrap classes
                            ext/      extension classes
By default, the Java interpreter looks for classes in the following order:

  1. the bootstrap classes

  2. extension classes

  3. user classes defined in one of a number of ways

Beyond the standard bootstrap classes and extension classes, the user can define one or more locations for user classes in a number of ways, as shown in this list which is in order of increasing priority:

  1. a default user class path of "."

  2. the CLASSPATH environment variable

  3. the Java interpreter -cp or -classpath options

  4. the -jar for identifying a single .jar file

If you need any help beyond what's in this section, it's time to pick up a good book on Java.