Chapter 15. Packages and Packaging

15.0 Introduction

One of the better aspects of the Java language is that it has defined a very clear packaging mechanism for categorizing and managing its large API. Contrast this with most other languages, where symbols may be found in the C library itself or in any of dozens of other libraries, with no clearly defined naming conventions.1 APIs consist of one or more package, packages consist of classes, and classes consist of methods and fields. Anybody can create a package, with one important restriction: you or I cannot create a package whose name begins with the four letters java. Packages named java. or javax. are reserved for use by Oracle’s Java developers, under the management of the Java Community Process (JCP). When Java was new, there were about a dozen packages in a structure that is very much still with us, though it has quadrupled in size; some of these packages are shown in Table 15-1.

Table 15-1. Java packages basic structure
Name Function

java.awt

Graphical user interface

java.io

Reading and writing

java.lang

Intrinsic classes (String, etc.)

java.lang.annotation

Library support for annotation processing

java.math

Math library

java.net

Networking (sockets)

java.nio

“New” I/O (not new anymore): channel-based I/O

java.sql

Java database connectivity

java.text

Handling and formatting/parsing dates, numbers, messages

java.time

Java 8: modern date/time API (JSR-311)

java.util

Utilities (collections, date) ...

Get Java Cookbook, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.