Package

Package is collection of similar classes, interfaces. Package provide name space management. Name space management involve managing various classes without any conflicts. Package also provide access protection to a group of related classes. Java application normally are collectoin of huge number of classes, it make sense that all related classes should be grouped. Java also has a number of packages known as API(application programming interface).



Syntax to create Package


	package <package_name>;
	

Any class or interface which you want to keep in a package named app in those files, first statement should be package app;
Now all those classes you have to save in a directory with same name as package.

For example lets say we are having one interface and one class. We want to organize this class and interface in a package app.

Example :


package app;
interface one
{
void show();
void print();
}

First line in above code specify that interface one is belongs to package app . In order to organize interface one in package app, file has to be placed in a directory with same name as package.

Example :


package app;
class start implements one
{
void show()
{
System.out.println("show method");
}
void print()
{
System.out.println("print method");
}
}


We will compile above code and generated class file we will place in folder app This file also we will save in app directory.


After saving both files, folder app will be having two files one.class and start.class .



Use of package

Project have multiple modules, package helps programmer to organize project into functionality wise modules. Package also provide access protection mechanism