Java Reference
In-Depth Information
Chapter 7. Packages
Programs are organized as sets of packages. Each package has its own set of names for types,
which helps to prevent name conflicts.
declared
public
.
The naming structure for packages is hierarchical (§
7.1
). The members of a package are
subpackages, which may contain compilation units and subpackages of their own.
a file system may have certain constraints on the organization of their compilation units to
allow a simple implementation to find classes easily.
ally has access to all types declared in its package and also automatically imports all of the
public
types declared in the predefined package
java.lang
.
For small programs and casual development, a package can be unnamed (§
7.4.2
) or have a
simple name, but if code is to be widely distributed, unique package names should be chosen
using qualified names. This can prevent the conflicts that would otherwise occur if two de-
velopment groups happened to pick the same package name and these packages were later
to be used in a single program.
7.1. Package Members
For example, in the Java SE platform API:
• The package
java
has subpackages
awt
,
applet
,
io
,
lang
,
net
, and
util
, but no com-
pilation units.
• The package
java.awt
has a subpackage named
image
, as well as a number of
compilation units containing declarations of class and interface types.
If the fully qualified name (§
6.7
) of a package is
P
, and
Q
is a subpackage of
P
, then
P.Q
is
the fully qualified name of the subpackage, and furthermore denotes a package.