Java Reference
In-Depth Information
begins with a directory name.
Here are package names that can be used to reference class
OneClass
:
package1
vc.package1
prog.vc.package1
Gries.prog.vc.package1
Such complicated package names are used because packages can contain
other packages. For example, package
java
contains no classes but many sub-
packages. One of these is package
java.lang
, which contains classes
String
and
Math
and the wrapper classes like
Integer
. Package
java.lang
also con-
tains subpackage
java.lang.reflect
.
So you see that there is good reason to allow a package name to be a
sequence of directory names separated by periods.
The class path
Java has to know where the directories corresponding to packages are placed
on your computer. Each operating system has a different way of indicating this.
We discuss the issue assuming that we are working on a Windows system.
Class
TwoClass
, above, imports the classes of package
package1
using :
import
package1;
The path to this directory is:
C:\Gries\prog\vc\package1
The import statement tells Java what the suffix of the path is:
package1
. But how
is Java supposed to know where this directory is located? In other words, how
does Java know the prefix that precedes
package1
on this path? Java does not
know unless it is told. This is done using an environment variable of the operat-
ing system, called
CLASSPATH
.
Your program may be using several packages that are on totally different
paths, so variable
CLASSPATH
may have to contain several different prefixes.
Here is an example of
CLASSPATH
with two prefixes. The prefixes are terminat-
ed with semicolons:
C:\Gries\prog\vc;C:\VisualCafe\Java\Src;
If you are using an IDE, you do not have to worry about
CLASSPATH
. The
IDE either sets it for you automatically or provides a way for you to change it.
If you are using just a compiler and not a full IDE, you need to know more
about setting
CLASSPATH
. We explain this briefly, but get help before you try it.
On a Windows NT computer, look in the Control panel and click on the
System icon; in the window that emerges, click on the System Properties tab.
You should then be able to set variable
CLASSPATH
.
Search WWH ::
Custom Search