分类: Java
2010-07-13 11:28:18
Hist:
1007012, draft
Programs are organized as sets of packages. Each package has its own set of names for types, which help to prevent name conflict.
Package Members
The members of a package are its subpackages and all the top level class types and top level interface types declared in all the compilation units of the package.
A package may not contain two members of the same name, or a compile-time error results.
Host Support for Packages
Host determines how packages, compilation units, and subpackages are created and stored, and which compilation units are observable in a particular compilation. Packages can be stored in a file system or db.
Compilation Units
CompilationUnit is the goal symbol for the syntactic grammer of Java programs.
Package Declarations
A compilation unit that has no package declaration is part of an unnamed package. An unnamed package cannot have subpackages. An implementation of the Java platform must support at least one unnamed package.
Import Declarations
Single-Type-Import Declaration
such as
import java.util.Vector;
Type-Import-on-Demand Declaration
such as
import java.util.*;
Single Static Import Declaration
A single-static-import delcaration imports all accessible static members with a given simple name from a type.
such as
import static java.lang.System.out;
Static-Import-on-Demand Declaration
such as
import static java.lang.System.*;
Automatic Imports
Each compilation unit automatically imports all of the public type names declared in the predefined package java.lang, as if the declaration:
import java.lang.*;
Top Level Type Declarations
A top level type declaration declares a top level class type or a top level interface type. By default, the top level types declared in a package are accessible only within the compilation units of that package, but a type may be declared to be public to grant access to the type from code in other packages.
Unique Package Names
1. JLS 3nd