10 - Java utilities  pp. 327-364

Java utilities

By Clark S. Lindsey, Johnny S. Tolliver and Thomas Lindblad

Image View Previous Chapter Next Chapter


Any language should come with a well-stocked toolbox of utilities to ensure programming 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.

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.

Collections Framework, documentation at Sun Microsystems, http://java.sun.com/j2se/1.5.0/docs/guide/collections/
Java Tutorial: Internationalizations, Sun Microsystems, http://java.sun.com/books/tutorial/il8n/index.html
Regular Expressions – The Java Tutorial, Sun Microsystems, http://java.sun.com/docs/books/tutorial/extra/regex/
Brett McLaughlin and David Flanagan, Java 1.5 Tiger, A Developer's Notebook, O'Reilly, 2004
Calvin Austin, J2SE 1.5 in a Nutshell, May 2005, http://java.sun.com/developer/technicalArticles/releases/j2se15/
Java 2 Platform, Standard Edition, API Specification, http://java.sun.com/j2se/1.5/docs/api/
java.util.regex.Pattern specification, http://java.sun.com/j2se/1.5.0/docs/api/java/util/regex/Pattern.html
Ronald Mak, The Java Programmer's Guide to Numerical Computing, Prentice Hall, 2003