Chapter 21. Packages and Packaging

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.[59] APIs consist of one or more packages; packages consist of classes; 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 are shown in Table 21-1.

Table 21-1. Java packages basic structure
NameFunction

java.applet

Applets for browser use

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)

java.util.regex

Regular Expressions ...

Get Java Cookbook, 3rd 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.