Java package


A package is a collection of related classes and interfaces providing access protection and namespace management. The classes are easier to find and to use, to avoid naming conflicts and to control access, programmers bundle groups of related classes and interfaces into packages.

There are two type of packages
1. built-in package
2. user-defined package
The package keyword is used to create a package.

//save package as
package pack;
class sample
public static void main(String args[])
System.out.println(“Welcome India “);

Advantages of java package

Packages hide the classes and interfaces that are used by the package but are not visible or accessible outside the package.

Classes and interfaces in packages can have fields and methods that are visible by all classes inside the package, but not another package.

Different packages can have classes with the same name. For example, java.awt.Frame and photo.Frame.

Package are useful to arrange related classes and interface into a group. This makes all the classes and interfaces performing the same task to put together in the same package.


Leave a Reply

Your email address will not be published. Required fields are marked *