Java Reference
In-Depth Information
Chapter 10
Java utilities
10.1 Introduction
Any language should come with a well-stocked toolbox of utilities to ensure pro-
gramming efficiency and convenience. The Java core language, in fact, includes
a large package named, quite sensibly, java.util that holds classes to handle
arrays, hash tables, time keeping, and other common tasks. In this chapter, we
focus mostly on this package but also discuss some handy tools in other packages
such as String and StringBuffer in java.lang and StringBuilder and
enum , that were added to java.lang for J2SE 5.0 [1,2]. We also discuss the
Collections Framework and the new Generics feature of J2SE 5.0.
We also look at classes and techniques for handling numbers at two extremes.
For bits we have the java.util.BitSet class. For arbitrarily large numbers
and for those that with very long decimal fractions we have the java.math.
BigInteger and java.math.BigDecimal classes.
We can only briefly describe here the general workings of these classes, many
of which contain a great number of methods. See the class descriptions in the
Java 2 API Specifications for the full details.
10.2 The java.util Package
The package java.util has been part of the core language since Java 1.0.
However, several classes have been added in subsequent versions. As the name
suggests, the classes in this package serve a number of useful utility purposes,
and we discuss several of them in this chapter. These include:
Vector - unlike an array, Vector objects contain a list of objects that can grow or
shrink
Enumeration , Iterator - convenience classes for cycling one item at a time through
a list
Hashtable , Properties and HashMap - associative arrays that hold key/value pairs
Preferences -aset of classes to maintain user preference settings in a program
StringTokenizer - search and parse strings
Date , Calendar - tools for handling dates and time values
327
Search WWH ::




Custom Search