Syntax
>>-package-PackageName-;-><
Description
A package declaration in a compilation unit specifies the name of the package
to which the compilation unit belongs. A compilation unit that has no package declaration
is part of an unnamed package.
The package name mentioned in a package declaration must be the fully qualified name of the package. If a type named T is declared in a compilation unit of a package whose fully qualified name is P, then the fully qualified name of the type is P.T.
A package can have subpackages or types declared in compilation units. For example, in the standard Java API, the package java has subpackages awt, applet, io, lang, net, and util, but no compilation 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.
Compilation Units
A compilation unit consists of three parts, each of which is optional:
Every compilation unit automatically and implicitly imports every public type name declared in the predefined package java.lang, so that the names of all those types are available as simple names.
Example
In the following example, the fully qualified name of class Point is wnj.points.Point:
package wnj.points; class Point { int x, y; }
Syntax diagrams
class keyword
import keyword
interface keyword
Source: The Java Language Specification. Copyright (C) 1996 Sun Microsystems, Inc.