Components of the standard Java class library
The Java Class Library (JCL), often referred to as the Java standard library, contains thousands of classes and interfaces, written almost entirely in Java,1 providing a wide range of capabilities. No Java application or library (not even a single Java class) can be written without reference (whether explicit or implicit, direct or indirect) to at least one class in this library. On the other hand, many non-trivial Java applications and libraries make use of no other libraries beyond the JCL.
This outline, and the selected descriptions below, are not intended to give a complete picture of the JCL, but only to summarize its most commonly used packages.
java
: Root package for library core
java.awt
: Abstract Window Toolkitjava.io
: Basic input/outputjava.lang
: Core object typesjava.net
: Basic network addressing & accessjava.math
: Arbitrary-precision numeric types & operationsjava.nio
: High-level extensions to input/output features
java.security
: Security frameworkjava.sql
: Basic RDBMS accessjava.text
: Locale-independentjava.time
: Dates, times, intervalsjava.util
: Collections framework & other utilities
java.util.concurrent
: High-level concurrencyjava.util.function
: Core functional interfacesjava.util.jar
: Operations on JAR (Java Archive) filesjava.util.prefs
: Preferences & configuration settings managementsjava.util.regex
: Regular expressionsjava.util.stream
: Functional operations on streams of valuesjava.util.zip
: Operations on ZIP and GZIP filesjavax
: Root package for library extensions
javax.crypto
: Cryptographic operationsjavax.script
: Scripting language supportjavax.sql
: Enterprise RDBMS accessjavax.swing
: Swing GUI libraryjavax.xml
: XML processingjava.awt
: Abstract Window ToolkitThe Abstract Window Toolkit (AWT) was the first GUI toolkit available for Java. It’s considered a “heavyweight” GUI toolkit, since all of the elements are implemented directly in terms of the corresponding elements in the underlying operating system, rather than taking advantage of Java capabilities for memory, display, and control management.
Currently, almost none of the GUI code we write uses AWT elements directly. In particular, we don’t use AWT in Android programming: the only elements of AWT that are included in the Android standard library are the NumericShaper
, NumericShaper.Range
, and TextAttribute
classes, used primarily in computing font metrics. On the other hand, even indirect dependencies can complicate things: some 3rd-party Java libraries we’d like to use have AWT dependencies, so our code would depend on AWT indirectly—which would (for example) make it impossible for us to use such a library in an Android app.
java.io
: Basic input/outputThis contains interfaces and classes for reading/writing data from/to byte-level streams associated with files, network connections, and memory buffers; reading and writing char
and higher-level primitive and class values; reading and writing file metadata (name, size, permissions, and other attributes); creating and deleting files and directories.
java.lang
: Core object typesThe interfaces and classes in this package provide a significant portion of the runtime infrastructure for even the most basic Java applications. For example, every class extends (directly or indirectly) the java.lang.Object
class, and every Java application includes a main
method that takes an array of java.lang.String
references as a parameter. Those 2 classes—and several others in this package—play key roles in the Java language itself, and are given special treatment by the Java compiler.
This is the only package that is automatically imported by javac
(the Java compiler). However, this automatic import is only for the java.lang
package itself, and not any subpackages (e.g. java.lang.reflect
).
java.net
: Basic network addressing & accessThis package includes low-level (e.g. IP addresses and sockets) and high-level (e.g. connections, URLs, and URIs) classes and interfaces for network operations.
java.math
: Arbitrary-precision numeric types & operationsBeyond the numeric primitive types (byte
, char
, short
, int
, long
, float
, double
) and the corresponding wrapper classes (Byte
, Short
, Integer
, Long
, Float
, Double
)2, there are 2 classes in the java.math
package of the standard library that support integer values of arbitrary size, floating-point values of arbitrary precision, and operations on those values: BigInteger
and BigDecimal
. There are theoretical limits on the size and precision of values of these types—but for most practical purposes, the operative constraint is system memory.
Note that the Math
class, which defines a wide range of methods for performing calculations on the primitive numeric types, is not part of the java.math
package; instead, it is in java.lang
.
java.nio.file
: Filesystem operationsThis package extends the features of java.io
to provide high-level access to directory and file contents. This package was introduced in Java 1.7, and extended significantly to support the streams framework introduced in Java 1.8.
java.util
: Utility classes and interfacesThis package contains the classes and interfaces of the Java Collections Framework, defining an extensive set of collections (lists, sets, and maps), and implementing key algorithms that operate on those collections. In addition, this package contains classes for managing dates, times, and calendars; basic text formatters and input tokenizers; classes providing utility operations on arrays and other objects; timers; null-aware container classes; etc.
(As seen from the abbreviated list above, the subpackages of this package are similarly extensive and varied.)
Some portions of the JCL involve platform-specific use of OS services: graphics display, networking, filesystem, etc. These low-level integrations are typically written in C, and integrate with the JCL via the Java Native Interface (JNI). ↩
There is a Character
wrapper type, corresponding to the char
primitive type; however, Character
is not a subclass of Number
, so it is not considered a numeric object type. ↩