CHAPTER 21: The Package java.util Previous
Previous
Java Language
Java Language
Index
Index
Next
Next

The Package java.util

The java.util package contains various utility classes and interfaces.

Notable among these utilities is the Enumeration interface (S21.1). An object that implements this interface will generate a series of items, delivering them on demand, one by one. Container classes such as Dictionary and Vector provide one or more methods that return an Enumeration.

A BitSet (S21.2) contains an indexed collection of bits that may be used to represent a set of nonnegative integers.

The class Date (S21.3) provides a convenient way to represent and manipulate time and date information. Dates may be constructed from a year, month, day of month, hour, minute, and second, and those six components, as well as the day of the week, may be extracted from a date. Time zones and daylight saving time are properly accounted for.

The abstract class Dictionary (S21.4) represents a collection of key-value pairs and allows a value to be fetched given the key. The class Hashtable (S21.5) is one concrete implementation of Dictionary. The class Properties (S21.6) extends Hashtable by allowing one table to provide default values for another and by providing standard means for reading entries from files and writing entries to files.

The class Observable (S21.7) provides a mechanism for notifying other objects, called "observers," whenever an Observable object is changed. An observer object may be any object that implements the Observer interface (S21.8). (This notification mechanism is distinct from that provided by the wait and notify methods of class Object (S20.1) and is not connected with the thread scheduling mechanism.)

The class Random (S21.9) provides an extensive set of methods for pseudorandomly generating numeric values of various primitive types and with various distributions. Each instance of class Random is an independent pseudorandom generator.

A StringTokenizer (S21.10) provides an easy way to divide strings into tokens. The set of characters that delimit tokens is programmable. The tokenizing method is much simpler than the one used by the class java.io.StreamTokenizer. For example, a StringTokenizer does not distinguish among identifiers, numbers, and quoted strings; moreover, it does not recognize and skip comments.

The classes Vector (S21.11) and Stack (S21.12) are simple container classes that provide extensions to the capabilities of Java arrays. A Vector, unlike a Java array, can change its size, and many convenient methods are provided for adding, removing, and searching for items. A Stack is a Vector with additional operations such as push and pop.

The hierarchy of classes defined in package java.util is as follows. The classes Object (S20.1) and Throwable (S20.22) are in package java.lang. The classes EmptyStackException (S21.13) and NoSuchElementException (S21.14) are in package java.util.

Object
	interface Enumeration
	BitSet
	Date
	Dictionary
		Hashtable
			Properties
	Observable
	interface Observer
	Random
	StringTokenizer
	Vector
		Stack
	Throwable
		Exception
			RuntimeException
				EmptyStackException
				NoSuchElementException


Top© 1996 Sun Microsystems, Inc. All rights reserved.