Defining a package
To make a package is quite simple: easy include a package command as the first statement in a Java source file. Any classes declared inside that file will belong to the specified package. A package statement defines a name space in that classes are stored. The class names are out into the default package if you omit the package statement that has no name. Although the default package is fine for short, example programs, it is inadequate for real applications. Most of the time, you will declare a package for your code.
This is the common form of the package statement:
Package pkg;
In the given form, pkg is the name of the package. For instance, the following statement creates a package known as Mypackage.
package Mypackage;
Java uses file system directories to store those packages. For instance, the .class files for any classes you define to be a part of Mypackage has to be stored in a directory known as Mypackage. Note that case is significant and the directory name have to be matching the package name exactly.
More than one file can involved the similar package statement. The package statement easily specifies to that package the classes described in a file belong. That does not exclude the other classes in other files from being part of that similar package. Most real- world packages are spread across various files.
You can make a hierarchy of packages. To do so, easily separate every package name from the one above it through use of a period. The common form of a multileveled package statement is displays here:
package pkg1[.pkg2[pkg3]];
A package hierarchy has to be reflected in the file system of your java development system. For instance, a package defines as package java.awt.image;
Requires to be stored in java:awt:image or java/awt/image,java\awt\image, on your system UNIX, windows, or Macintosh file system, respectively. Be sure to select your package names carefully. We cannot rename a package without renaming the directory in that the classes are stored.