Tech moves fast! Stay ahead of the curve with Techopedia!
Join nearly 200,000 subscribers who receive actionable tech insights from Techopedia.
In the context of Java, a package is an organized and functionality based set of related interfaces and classes. Packages organize classes that belong to the same category or provide similar functionality. Classes facilitate class downloads in groups and may be stored in compressed files, like Java Archive (JAR) files.
Package names should be unique, and a package class may access package access members for other package classes.
Java packages are similar to labeled computer folders. For example, most users prefer keeping HTML pages, images, and scripts in different folders for better organization. Likewise, there are many classes and interfaces in the Java language. Programmers prefer organizing related classes and interfaces in different directories. Thus, a particular package contains interrelated classes and interfaces.
Generally, a Java package may contain classes, interfaces, Java annotations and enumerated types. To define a class package, the package keyword is used in the source file for that class and is usually the first keyword in the source file. For example, if a class named Foo belongs to a package named com.mypackage, the following line should exist at the beginning of the Foo Java source file: package com.mypackage.