A java package is a group of similar types of classes, interfaces and sub-packages.
Package in java can be categorized in two form, built-in package and user-defined package.
There are many built-in packages such as java, lang, awt, javax, swing, net, io, util, sql etc.
There are several advantages of using Java Packages, some of them, are as follows –
1)Make easy searching or locating of classes and interfaces.
2)Avoid naming conflicts. For example, there can be two classes with the name Student in two packages, university.csdept.Student and college.itdept.Student
Implement data encapsulation (or data-hiding).
3)Provide controlled access: The access specifiers protected and default have access control on package level. A member declared as protected is accessible by classes within the same package and its subclasses. A member without any access specifier that is default specifier is accessible only by classes in the same package.
4)Reuse the classes contained in the packages of other programs.
5)Uniquely compare the classes in other packages.
Types of Packages in Java
They can be divided into two categories:
1)Java API packages or built-in packages
2)User-defined packages.

Java API packages or built-in packages
Java provides a large number of classes grouped into different packages based on a particular functionality.
Examples:
•java.lang: It contains classes for primitive types, strings, math functions, threads, and exceptions.
•java.util: It contains classes such as vectors, hash tables, dates, Calendars, etc.
•java.io: It has stream classes for Input/Output.
•java.awt: Classes for implementing Graphical User Interface – windows, buttons, menus, etc.
•java.net: Classes for networking
•java. Applet: Classes for creating and implementing applets

.User-defined packages
As the name suggests, these packages are defined by the user. We create a directory whose name should be the same as the name of the package. Then we create a class inside the directory.