Home  |   STIU  |   WOW  |   SCJP  |   SCDJWS   |   JEE FAQ  |   About US  |  

FAQ
  Java FAQ
  JSP FAQ
  Servlet FAQ
 

Advertisement

XyzWs Java FAQ:
What is the default package?


Printer-friendly version Printer-friendly version | Send this 
article to a friend Mail this to a friend


Previous Next vertical dots separating previous/next from contents/index/pdf Contents
Advertisement
XyzWs Java FAQ: What is the default package?

What is the default package?

The default package is an unnamed package. The unnamed package contains java classes whose source files did not contain a package declaration. The purpose of default packahe is for convenience when developing small or temporary applications or when just beginning development.The compiled class files will be in the current working directory.

In 7.4.2 Unnamed Packages in Java Language Specification(Third Edition):

A compilation unit that has no package declaration is part of an unnamed package.

Note that an unnamed package cannot have subpackages, since the syntax of a package declaration always includes a reference to a named top level package.

An implementation of the Java platform must support at least one unnamed package; it may support more than one unnamed package but is not required to do so. Which compilation units are in each unnamed package is determined by the host system.

In implementations of the Java platform that use a hierarchical file system for storing packages, one typical strategy is to associate an unnamed package with each directory; only one unnamed package is observable at a time, namely the one that is associated with the "current working directory." The precise meaning of "current working directory" depends on the host system.

Unnamed packages are provided by the Java platform principally for convenience when developing small or temporary applications or when just beginning development.

How to import classes that are in the default package? is another interesting topic to read.


Previous Next vertical dots separating previous/next from contents/index/pdf Contents

Support  | Feedback  | Help