Sitemap

Packages in java

2 min readOct 23, 2026

--

In Java, packages are used to group related classes, interfaces, enums and sub package.

It helps to organize code, avoid naming conflicts and control access makes large applications easier to maintain.

Press enter or click to view image in full size

Types of packages in java

There are primarily two types of packages in java,

  1. User defined package

User defined packages are created by programmers to organize application specific classes and interfaces.

2. Built in package

Built in packages are provided by the java API. They contain common classes and interfaces for common programming task.

Some of common important built in packages are:

java.lang : contains fundamental classes and interfaces that support core java function such as String, Math, System and Wrapper classes like Integer, Double and Boolean. This package is automatically imported.

Java.io : contains class for supporting input/output operations.

java.util : contains utility classes that implement data structures such as LinkedList, Dictionaries as wells as support for date and time operations.

java.awt: awt stands for abstract window toolkit. Contains classes for implementing the components for graphical user interfaces like buttons, menu etc.

Press enter or click to view image in full size
Package types

Lets understand what happens when we write

import java.util.ArrayList;

What is import?

In Java, import tells java we want to use classes and interfaces without writing its full name.

Get Vignesh’s stories in your inbox

Join Medium for free to get updates from this writer.

without import, we have to use its full qualified name

java.util.ArrayList<String> list=new java.util.ArrayList<>();

What is java?

java is a top level package name.

Java organizes its built in classes into groups called packages.

For example :

  • java.util
  • java.io
  • java.lang

What is util?

A package containing useful class and tools.

util is short for utilities.

what is ArrayList?

ArrayList is a resizeable array that contains several used method to store and manipulate group of objects efficiently.

Access Modifiers in java

Access modifiers controls who can access a class, variable, method or constructor.

Java has four important access modifier those are,

  • public→ Accessible everywhere.
  • private → Accessible only within the same class.
  • protected →Accessible within same package(both subclass and non subclass) and subclass of other package.
  • default → Accessible within the same package(both subclass and non subclass). It is also called package private access.

--

--