Java Reference
In-Depth Information
Java syntax: Import statement
import package-name . *;
Example : import javax.swing.*;
Purpose : Allow classes in package package-name to be referenced directly.
import package1.*;
imports all the classes of package package1 . This form of the import statement,
used in the following definition of class TwoClass , is used frequently:
import package1.*;
import package1.OneClass;
public class TwoClass {
public void m() { ... }
}
File TwoClass.java now imports method OneClass twice —in the first and
second import statements. There is nothing wrong with this, although the second
import statement is unnecessary and can be deleted.
11.2
Package names
The directory that contains package package1 may be buried a few levels down
on hard drive C in a Windows environment. Here is the path to the directory on
one laptop:
Windows: C:\Gries\prog\vc\package1
In a Unix environment, the forward slash symbol is used to separate the
items on the path, and a slash typically begins the path as well:
Unix: /usr/Gries/prog/vc/package1
On the Macintosh, the first item of a path is the name of a hard drive or some
other device, and the colon is used to separate items on the path:
Macintosh: Macdisk:Gries:prog:vc:package1
All three systems use the same hierarchical concepts for storing directories
and files; they just use different formats to display paths.
In Java, this path is written without the beginning drive name and with peri-
ods separating the directory names:
Java-path : Gries.prog.vc.package1
In Java, then, we define a package name as follows:
Package name : a package name is any suffix of a Java-path that
Search WWH ::




Custom Search