Java Reference
In-Depth Information
The name of this class ( HelloWorld ), its source filename (HelloWorld.java),
and its output file (HelloWorld.class) all have the same name. Because of this, the
runtime system can easily find the class file for HelloWorld when it is first needed
by looking for a file named HelloWorld.class. Notice that the Java compiler needs
the .java extension, but the runtime system assumes the .class extension.
CLASSPATH
But where does the runtime system look for the HelloWorld.class?
In most cases, this is controlled with the CLASSPATH setting. The CLASSPATH
setting details a list of directories (or class archives, which can be jar or zip files) on
the host operating system that contain classes. The Java runtime searches these di-
rectories (in the order they are listed) for your class files as they are required. This is
similar to the way the PATH variable is used in Windows to find executable program
files. The CLASSPATH variable can be set either as an environment variable (that is,
a variable defined to the operating system) or as an optional argument to the run-
time instance. The optional argument at runtime is the preferred approach because
it doesn't mess up other programs' class paths.
For example, the standalone SDK runtime interpreter searches the
c:\java4cobol directory for your classes, given this runtime option:
java -cp c:\java4cobol HelloWorld
The -cp command argument tells the runtime to search in the c:\java4cobol di-
rectory for classes. The CLASSPATH argument can be a list of directories as well.
java -cp c:\windows\java;c:\java4cobol HelloWorld
The CLASSPATH can also include zip or jar files (archive files built by the jar
utility) that contain packages bundled by zip or jar utilities. I will say more about
this later.
Normally, you will not need to include the standard runtime classes; Java provides
a mechanism to find these automatically.
The system environment variable CLASSPATH works in much the same fash-
ion as the CLASSPATH command line argument. It can contain a list of directories
in which the runtime system can search for classes. Its use is discouraged, however,
Search WWH ::




Custom Search