Java Reference
In-Depth Information
variable tells Java where to begin its search for a package. It is not a Java variable. It is
an environment variable that is part of your operating system. The value of your
CLASSPATH variable is a list of directories. The exact syntax for this list varies from
one operating system to another, but it should be the same syntax as that used for the
(ordinary) PATH variable. When Java is looking for a package, it begins its search in the
directories listed in the CLASSPATH variable.
The name of a package specifies the relative path name for the directory that
contains the package classes. It is a relative path name because it assumes that you
start in one of the directories listed in the value of your CLASSPATH variable. For
example, suppose the following is a directory listed in your CLASSPATH variable
(your operating system might use / instead of \):
\libraries\newlibraries
And suppose your package classes are in the directory
\libraries\newlibraries\utilities\numericstuff
In this case, the package should be named
utilities.numericstuff
and all the classes in the file must start with the package statement
package utilities.numericstuff;
The dot in the package name means essentially the same thing as the \ or /, whichever
symbol your operating system uses for directory paths. The package name tells you
(and Java) what subdirectories to go through to find the package classes, starting from a
directory on the class path. This is depicted in Display 5.22. (If there happen to be two
directories in the CLASSPATH variable that can be used, then of all the ones that can
be used, Java always uses the first one listed in the CLASSPATH variable.)
Any class that uses the class in this utilities.numericstuff package must
contain either the import statement
import utilities.numericstuff.*;
or an import statement for each class in the package that is used.
The way you set the value of your CLASSPATH variable depends on your operating
system, but we can give you some suggestions that may work. The CLASSPATH
variable is usually spelled as one word with all uppercase letters, as in CLASSPATH . You
will probably have a plain old PATH variable that tells the operating system where to
find the code for commands such as javac and other commands that you can give as
single-line commands. If you can find out how to set the PATH variable, you should
be able to set the CLASSPATH variable in the same way.
 
Search WWH ::




Custom Search