Home : Course Map : Chapter 5 : Java :
CLASSPATH Environmental Variable
JavaTech
Course Map
Chapter 5
File/Package/Import
  Demo 1
  Demo 2
Access/Visibility
final & Constants
Static Import
Jar Files
  Demo 3
Applet Directories
3rd Party Packages
CLASSPATH
javadoc
CodingConventions
Exercises

    Supplements
Scope
Debug Techniques
Java Runtime
Class Class
JVM Instructions 2
JVM Processing
pack200

     About JavaTech
     Codes List
     Exercises
     Feedback
     References
     Resources
     Tips
     Topic Index
     Course Guide
     What's New

A path environment variable will indicate on a given platform where to find the JDK or JRE binary executables. For example, the path on a Windows platform might look like

  PATH=C:\WINDOWS;C:\WINDOWS\COMMAND;c:\java\j2sdk1.4.0\bin;

so that the c:\java\j2sdk1.4.0\bin directory will be searched for java executables. The executables will look relative to this directory for the core class files in rt.jar and other jars. The SDK or JRE installation places directories as follows:

           j2sdk1.4.0
   ____________|_______
   |   |     |   |    |
   bin lib   |  demo  |
             |       jre
             |      __|__
          include  |     |
                  bin   lib

(Typically under the c:\Program Files\Java\ directory on a MS Windows platform.

The bin directory contains the set of Java tools, such as the compiler (javac.exe) and JVM (java.exe), that you use to develop and run Java programs. The jre (Java Runtime Environment) directories contain the files needed to run Java programs but not the development tools such as the compiler. The jre would be distributed with a program intended for users who do not need the development tools.

The include directory contains files for linking Java programs to C or C++ code (see Chapter 22), and a set of demonstration programs come in the demo directory.

What about the user class files? When you run java or javac from the command line, the JVM will by default look in that directory and its subdirectories (according to the package names).

To find packages in other directories, you must enter the directories in the CLASSPATH environment variable. For example, suppose that the file Bessel.class is located in

 c:\programs\myJava\func\Bessel.class

Then

 > set CLASSPATH c:\programs;

will locate Bessel.class such as in the following example subclass definition:

 public class MyNewBessel extends myJava.func.Bessel {..

Similarly, when an import statement indicates to the compiler what packages to examine to locate a class, the classpath will direct it to the proper directories

   import myJava.functions.*;
   public class MyNewBessel extends Bessel {..

The classpath can also be set in the command line as in :

 c:\> javac -classpath c:\programs MyNewBessel

for compilation and

 c:\> java -cp c:\programs MyNewBessel

for running the program.

See Chapter 5: Java : JARS for directions on setting the classpath option to locate classes in JAR files.

References and Web Resources

Last update: Oct.24, 2004

            Tech
DecimalFormat
  Demo 1
  Demo 2

System.out.printf
  Demo 3
CJ Format Class
  Demo 4   Demo 5
Other Format Tools

Immutable Complex
Exercises

           Physics
Interpolation
Integration
  Demo 1
Simpson Rule
  Demo 2
Exercises

  Part I Part II Part III
Java Core 1  2  3  4  5  6  7  8  9  10  11  12 13 14 15 16 17
18 19 20
21
22 23 24
Supplements

1  2  3  4  5  6  7  8  9  10  11  12

Tech 1  2  3  4  5  6  7  8  9  10  11  12
Physics 1  2  3  4  5  6  7  8  9  10  11  12

Java is a trademark of Sun Microsystems, Inc.