Java Reference
In-Depth Information
The
org\cadenhead\library
subfolder of the folder where the
java
command
was entered. (For example, if the command was made from the
C:\J21work
folder,
the
BookShipper.class
file could be run successfully if it was in the
C:\J21work\
org\cadenhead\library
folder.)
n
The
org\cadenhead\library
subfolder of any folder in your
Classpath
setting.
n
The
org\cadenhead\library
subfolder of a Java archive file (JAR) in your
Classpath
.
n
One way to manage your own packages and any others you use is to add a folder to your
Classpath
that serves as the root folder for any packages you create or adopt, such as
C:\javapackages
or something similar. After creating subfolders that correspond to the
name of a package, place the package's class files in the correct subfolder.
The
import
Declaration
To import classes from a package, use the
import
declaration as you have throughout the
examples in the first week. You can import an individual class, as in this statement:
import java.util.Vector;
You also can import an entire package of classes using an asterisk (
*
) in place of an indi-
vidual class name, like this:
import java.awt.*;
The asterisk can be used in place of a class name only in an
import
statement. It does
not make it possible to import multiple packages with similar names.
For example, the Java class library includes the
java.util
,
java.util.jar
, and
java.util.prefs
packages. You could not import all three packages with the following
statement:
import java.util.*;
This merely imports the
java.util
package. To make all three available in a class, the
following statements are required:
6
import java.util.*;
import java.util.jar.*;
import java.util.prefs.*;
Also, you cannot indicate partial class names (for example,
L*
to import all the classes
that begin with L). Your only options when using an
import
declaration are to load all
the classes in a package or just a single class.