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

 

 

When you wish to create a class that is to belong to a named Java package, you must place a package statement as the first statement (i.e. first text other than comments and whitespace) in the class's Java source code file.

Here is a package statement:

package COM.Aardvark.eng.gui;

where the package name must be fully qualified -- that is, it must include the top-level package name and all intervening sub-package names .

A compilation unit that has no package statement is part of an unnamed package -- the default package.

  • A Java system is required to support at least one unnamed package
  • It may support more than one, but is not required to do so.
  • Unnamed packages are a convenience feature when developing simple or temporary development, or when just starting to learn Java.
  • Unnamed packages are strongly discouraged in real-world Java code.

Note: From this point on, I will expect you to use only named packages in your Java code!

This page was last modified on 02 October, 2007