Java Reference
In-Depth Information
Chapter 18. Packages
For some reason a glaze passes over people's faces when you say
"Canada". Maybe we should invade South Dakota or something.
Sandra Gotlieb, wife of Canadian ambassador to U.S. (19811989)
Packages define units of software that can be distributed independently
and combined with other packages to form applications. Packages have
members that are related classes, interfaces, and subpackages, and may
contain additional resource files (such as images) used by the classes in
the package. Packages are useful for several reasons:
Packages create groupings for related interfaces and classes. For
example, a set of library classes for performing statistical analysis
could be grouped together in a stats package. The package can be
placed in an archive file, together with a manifest describing the
package, and shipped to customers for use in their applications.
Packages create namespaces that help avoid naming conflicts
between types. Interfaces and classes in a package can use pop-
ular public names (such as List and Constants ) that make sense
in one context but might conflict with the same name in another
package.
Packages provide a protection domain for developing application
frameworks. Code within a package can cooperate using access to
identifiers that are unavailable to external code.
Let us look at a package for the attribute classes you saw in previous
chapters. We will name the package attr . Each source file whose classes
and interfaces belong in the attr package states its membership with its
package declaration:
package attr;
 
Search WWH ::




Custom Search