Java Packages
Java Packages
Java application programming interface (API) is a list of all classes that are part of the Java development
kit (JDK). It includes all Java packages, classes, and interfaces, along with their methods, fields, and
constructors. These prewritten classes provide a tremendous amount of functionality to a programmer.
A programmer should be aware of these classes and should know how to use them.
import java.util.*;
This is the import statement imports all the classes in the API’s java.util package and makes them
available to the programmer. If you check the API and look at the classes written in the java.util package,
you will observe that it includes some of the classes that are used often, such as Arrays, ArrayList,
Formatter, Random, and many others. Another Java package that has several commonly used classes is
the java.lang package. This package includes classes that are fundamental to the design of Java
language. The java.lang package is automatically imported in a Java program and does not need an
explicit import statement. Please note that some of the classes that we use very early in Java
programming come from this package. Commonly used classes in the java.lang package are: Double,
Float, Integer, String, StringBuffer, System, and Math.
User Defined Packages in Java
One of the most innovative features of Java is the concept of packages. Packages in Java are a
way to encapsulate a group of classes, interfaces, enumerations, annotations, and sub-
packages. Conceptually, you can think of java packages as being similar to different folders on
your computer.
User-defined packages are those which are developed by users in order to group related
classes, interfaces and sub packages. With the help of an example program, let’s see how to
create packages, compile Java programs inside the packages and execute them.