Java Packages - Packages In Java
Last updated on
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 ?
- Group the classes and interfaces.
- Restrict the accessibility of classes and interfaces.
- Easy pluggability of modules.
- Reusability of modules.
- Preventing naming conflicts.
- 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"); } }