Packages
Packages and interfaces are two of the basic parts of java program. In common, a java source file can hold any of the following four internal parts:
A single package statement
Any number of import statements
A single public class declarations
Any number of classes private for the package
Just one of these- the single public class declaration- has been used in the instance so far. The name of every example class was taken from the similar name space. This means in which a unique name had to be used for every class to prevent name collisions.
After a while, without a few ways to manage the name space you could run out of convenient and descriptive names for individual classes. You also required some way to be assured in which the name you select for a class will be reasonably unique and not collide along with class names selected by other programmers. Thankfully, Java gives a mechanism for partitioning the class name space into more manageable chunks. That mechanism is known as package. The package is a naming and a visibility controls both mechanisms. You can declare classes within a package which are not accessible through code outside that package.
You can also declare class members which are only exposed to other members of the similar package. That permits your classes to have intimate knowledge of every one, but not expose that knowledge to the rest of the world.