Chapter 23. 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
the external API. Contrast this with a language like C, where external
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 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 Sun Microsystems’ Java developers. When Java was new, there
were about a dozen packages in a structure that is very much still with
us; some of these are shown in Table 23-1.
Table 23-1. Java packages basic structure
Name | Function |
---|---|
| Applets for browser use |
| Graphical User Interface |
| Intrinsic classes (strings, etc.) |
| Networking (sockets) |
| Reading and writing |
| Utilities (collections, date) |
Many packages have since been added, but the initial structure has stood the test of time fairly well. In this chapter, I show you how to create and document your own packages, and then discuss a number of issues related to deploying your package in various ways on various platforms.
23.1. Creating a Package
Problem
You want to be able to import classes and/or ...
Get Java Cookbook, 2nd 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.