Compilation Units
Home ] Up ] Qualified Names ] The import Statement ] Automatic Import ] The package Statement ] [ Compilation Units ] Host Support for Packages ] Type Definitions ] Access Control ]

 

 

A Java compilation unit is defined in the Java Language Specification as:

CompilationUnit :
   PackageDeclarationopt ImportDeclarationsopt TypeDeclarationsopt
TypeDeclarations :
   TypeDeclaration
   TypeDeclarations TypeDeclaration
TypeDeclaration :
   ClassDeclaration
   InterfaceDeclaration
Notice the subscript "opt", which means optional.

The above means that a Java compilation unit consists of:

  • Optionally, a package declaration, followed by
  • Optionally, a set of one or more import declarations, followed by
  • Optionally, a set of one or more type declarations, each type declaration may comprise:
    • A class declaration, or 
    • An interface declaration (more about interfaces, soon)
 

This page was last modified on 02 October, 2007