QR Code for this Page
Java Packages

Java Packages

Packages In Java

What is a Package ?

Package is nothing but a directory which is containing classes and sub packages (sub directories). In other words package is a set of classes grouped together. You can specify the package using a package declaration package < package-name > as the first (non-comment) line in the class. To use the Java package use the Java package keyword as shown in below example.

Package in java can be categorized in to two categories.

  • Built in packages
  • User defined packages

Packages In Java

Package in Java is a mechanism to encapsulate a group of classes, sub packages and interfaces.

Why to use Package ?

Packages are used To group the classes and interfaces.

Java Package Advantages ?

  1. Group the classes and interfaces.
  2. Restrict the accessibility of classes and interfaces.
  3. Easy pluggability of modules.
  4. Reusability of modules.
  5. Preventing naming conflicts.
  6. Easy to locate classes and interfaces in package (directory).

What are the built in Packages in Java?

Some of the built in packages in Java are as follows.

In this java packages tutorial you can learn about above mentioned built in java packages.

Java Package Example

package mypackage;

public class Simple
{  
    public static void main(String args[])
    {  
        System.out.println("Welcome to Java Package Example");
    }
}