7.3. Compilation Units

CompilationUnit is the goal symbol (§2.1) for the syntactic grammar (§2.3) of Java programs. It is defined by the following productions:

CompilationUnit:    PackageDeclarationopt ImportDeclarationsopt TypeDeclarationsoptImportDeclarations:    ImportDeclaration    ImportDeclarations ImportDeclarationTypeDeclarations:    TypeDeclaration    TypeDeclarations TypeDeclaration

A compilation unit consists of three parts, each of which is optional:

• A package declaration (§7.4), giving the fully qualified name (§6.7) of the package to which the compilation unit belongs.

A compilation unit that has no package declaration is part of an unnamed package (§7.4.2).

import declarations (§7.5) that allow types from other packages and ...

Get The Java® Language Specification, Java SE 7 Edition, Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.