1. What is a Package?

A package is a way of grouping related Java classes, interfaces, and other types together.

It also provides a namespace to avoid naming conflicts.

Example:

package com.example.app;

Then the class belongs to that package.


2. Why Packages?

Main reasons:

Example:

com.company.model
com.company.service
com.company.controller

3. Import

import allows you to use a class from another package without writing its full package name.

import java.util.ArrayList;

ArrayList<Integer> list = new ArrayList<>();

Without import: