Table of Contents
One of the great strengths of Java is its large and powerful class library.
You can get an idea of the size and scope of the Java class library by going to the “javadoc” pages for the appropriate version of the JDK.
For example, click on this link: https://docs.oracle.com/javase/1.5.0/docs/api/ to go to the javadoc pages that describe the Java API for Java 5 (a.k.a. 1.5). (Of course, there are many later versions of Java than this.)
Browse around a little to see how much there is!
Of course, with any such rich and powerful class library, you have to spend a lot of time learning what is there, what to use for what you need, and how to use it. But don’t worry! You don’t have to know everything in the class library in order to use it. (I know I don’t!)
Overview
What is the Java Class Library?
Java comes with a very large and useful library of classes and interfaces.
The Java class library supports a large number of capabilities, too numerous to mention at this point.
The Organization of the Library
The following gives an idea of the organization of the java class library :
java
applet // applet support
awt // Abstract Windowing Toolkit (AWT)
datatransfer // Generic inter-app data transfer
event // Event handling
image // Image processing support
peer // GUI component peer interfaces
beans // Java Beans (reusable components)
io // I/O support
lang // Java language support
reflect // Java Reflection API
math // Math support
net // Network support
rmi // Remote Method Invocation (RMI)
dgc // Distributed Garbage Collection
registry // Remote object registration
server // Remote object creation
security // Cryptographic security
acl // Access Control List support
interfaces // Java Security API interfaces
sql // Java Database Connectivity (JDBC)
text // Internationalization support
util // "Utility" support (central)
zip // Data [de]compression support
Note: Each version of Java adds considerably to the Java class library, so it is impractical to keep the above up to date. If you wish to learn what is available in any given version of the Java class library, you should use your web browser to go to https://www.oracle.com/java/technologies/ and browse around, seeing how Java gets into lots of areas.
Class java.lang.Object
As the textbook says, the Object class is the “Cosmic Superclass” for Java.
Every class in Java ultimately extends from the Object class. It is the top of the Java inheritance hierarchy, which means that there is only a single inheritance tree in Java. (In C++, this is not true; there are as many inheritance trees as you wish to invent — you get a forest, not a single tree.)
To get a good feel for what is in the Object class, click on this link: https://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Object.html , which will show you the Object class for Java 5/1.5. Browse over it, to see what it supplies.
Here, we will talk about some of the features it provides.
java.lang Classes
Here is a quick synopsis of some of the classes you’ll find in the java.lang package:
Object
The ultimate root class of all Java classes
Class
A class that describes a Java class.
Wrapper Classes
These are:
- Boolean
- Character
- Number
- Byte (JDK 1.1)
- Short (JDK 1.1)
- Integer
- Long
- Float
- Double
These classes provide immutable wrappers for the primitive data types, when you wish to manipulate such types as objects — especially to allow for their use in polymorphism.
Number is an abstract class, from which the numeric wrappers all derive. All the other classes are final classes.
String, StringBuffer
Objects that represent strings.
String is an immutable type.
StringBuffer allows its string to be changed in place.
Runtime
Contains a number of low-level methods associated with the Java run-time system.
System
Contains a number of low-level methods associated with the system.
All its methods are class methods; it may not be instantiated.
Math
Provides support for the mathematical values e and Π (pi), and defines static methods for floating point trigonometry, exponentiation, minimum, maximum, and pseudo-random number generation.
All its methods are class methods; it may not be instantiated.
Thread
Provides support for multiple threads of control running within the same Java interpreter.
Process
Defines a platform-independent interface to platform-dependent processes running externally to the Java interpreter.
Throwable, Exception, Error, and Specific Exception Classes
Defines a set of objects that may be thrown as exceptions.
java.util Classes
The package java.util, as its name implies, provides a number of useful classes.
(Note: It should not be considered a “utility” package separate from the rest of the language. It is part and parcel of the library, and Java depends heavily on several of the classes in this package.)
The Old Collections Classes
HashTable and Properties
HashTable implements a hashtable or associative array. It allows abritrary objects to be stored and retrieved by arbitrary keys.
Properties, a subclass of HashTable, is used to store the Java system properties list.
Vector
Implements an array of objects that grows as needed when objects are added.
Stack
Implements a LIFO stack on which objects may be pushed and from which they may be popped.
Enumeration
Interface which provides a simple and consistent way to loop through all the elements contained within some kind of object or data structure.
The Collections Framework
Many interfaces and classes used to implement the powerful Java collections framework. We discussed these classes in some detail, earlier.
Date, Calendar, and TimeZone
The Date class represents a date and time, using a millisecond representation.
The Calendar class manipulates dates using years, months, days, hours, minutes, etc.
The TimeZone class is used in conjunction with dates.
ResourceBundle, ListResourceBundle, PropertyResourceBundle
Represent a “bundle” of localized resources that are read in by an internationalized Java program at run-time.
BitSet
Implements an arbitrary-size array of bits.
Random
Generates and returns pseudo-random numbers in a variety of forms.
StringTokenizer
Parses a string into tokens.
Observer and Observable
Provide infrastructure for implementing the object-oriented model-view paradigm in Java.
java.math Classes
The java.math package contains classes for arbitrary-precision integer and floating-point arithmetic.
BigDecimal
Represents a floating-point number of arbitrary size and precision.
Its methods duplicate the functionality of the standard Java arithmetic operators.
BigDecimal is a subclass of java.lang.Number.
BigDecimal values can be useful for applications (such as financial applications) where rounding errors are problematic.
BigInteger
Represents integers that can be arbitrarily large.
It defines methods which duplicate the functionality of the standard Java arithmetic and bit-manipulation operators.
BigInteger is a subclass of java.lang.Number.
Arbitrary-length integers are used in cryptography, and BigInteger contains many methods designed for cryptographic applications.
