Errata for
The Java Class Libraries: Second Edition, Volume 1
by
Patrick Chan, Rosanna Lee, and Douglas Kramer
If you find an error in the book,
please check this list first to see if it is already known.
If not, please mail us the relevant
information, including page numbers.
All errata will be fixed in the next possible printing.
The errata is categorized by the printing number of the book.
You can tell which printing you have by looking at the
bottom of the copyright page. The last line of that page
indicates the printing number.
Errata for All Printings
Integer
- Page 1002
- In the decode() entry in the Member Summary, replace
"16-bit" with "32-bit". The entry should read
Parses the string representation of a 32-bit signed integer into an
Integer.
Errata for First to Fourth Printings
Character.isIdentifierIgnorable()
- Page 292
- Remove the last four rows of Table 9 and add the following row.
\u007f - \u009f All characters that have the FORMAT generate category value
Character.isUnicodeIdentifierStart()
- Page 299
-
Change the last sentence in the DESCRIPTION section to read:
It is valid if it is a letter (either isLetter()
or a numeric letter such as a Roman numeral character).
FileOutputStream
- Page 822
-
In the class example, the (byte) cast is missing from the definition
of the buf variable. It should read as follows.
byte[] buf = {(byte)'h', (byte)'e', (byte)'l', (byte)'l', (byte)'o', (byte)'\n'};
Errata for First to Third Printings
java.text
- Page 29
- In the NumberFormat table, the description of ChoiceFormat says
it maps strings to numbers, when it maps in both directions. It
should say:
"A concrete class for formatting ranges of numbers to strings
and parsing strings to numbers. Used to associate numbers with
singular/plural nouns and for including named series in user
messages."
Array
- Page 49
-
Change Comparable to Comparator in
the first paragraph of the EXAMPLE description.
BigInteger.compareTo()
- Page 110
-
Change Comparable to Comparator in
the EXAMPLE description and in the sample code.
BreakIterator
- Page 150
-
The class diagram incorrectly includes the package-private
subclass SimpleTextBoundary.
Calendar.PM
- Page 267
-
The value of this constant is 1, not 0.
Character.forDigit()
- Page 287
-
In the DESCRIPTION section and in the example, 'A' should be 'a'.
That is, Character.forDigit(10, 16) returns 'a', not 'A'.
ChoiceFormat
- Pages 349, 350
-
The values you specify in a pattern for +infinity and -infinity are
\u221E and -\u221E. (With the proper font,
these appear as the infinity symbol, a sideways "8".) Also, step 3
shows the less-than or equal sign as being \u2064, when it should
be \u2264. Consequently, step 2 should be modified to appear as follows:
2. Convert the symbols to those allowed in patterns.
- Drop the uppermost relation and upper bound.
- For <=, substitute either # or \u2264 (the Unicode symbol for <=).
- In place of +Infinity, use
\u221E.
- In place of -Infinity, use
-\u221E. You can optionally
substitute any valid number in the first range. The number
you choose will be the number returned by the parse() method.
In addition, the one-line example patterns at the end of step 3
should show "-\u221E" in place of "-INF".
Class
- Page 365
-
In Figure 29, getSuperClass() should be getSuperclass().
Class
- Page 367
-
In Table 14,
the type descriptors for boolean[] and boolean[][]
are wrong. The table should read:
Primitive Type Array Type Descriptor
boolean[] [Z
boolean[][] [[Z
double[][] [[D
Class.getDeclaredFields()
- Page 379
-
The line
print(D.class.getDeclaredField("g")); // public int D.ci
should be replaced with:
print(D.class.getDeclaredField("g")); // float D.g
Class.getResource()
- Page 394, 396
-
In the EXAMPLE section, the last paragraph in the section should read:
Also included is some sample code for reading an image resource.
The object type that is returned by URL.getContent()
is platform-dependent. In the program, we test for two possibilities:
one as a java.awt.Image object and the other as an
java.awt.image.ImageProducer object.
In the sample code on Page 396, the code should read as follows:
if (o instanceof Image) {
image = (Image)o;
} else if (o instanceof ImageProducer) {
image = Toolkit.getDefaultToolkit().createImage((ImageProducer)o);
}
Class.isInstance()
- Page 402
-
In the EXAMPLE section,
the output of System.out.println(I.class.isInstance(d))
should be "false" instead of "true".
CollationElementIterator.primaryOrder(), secondaryOrder()
- Page 439, 440
-
To be consistent with the class description, the parameter
order
in primaryOrder(int order) should be renamed to
element, which changes the signature to
primaryOrder(int element). The same holds true
for secondaryOrder(int element) and
tertiaryOrder(int element).
Collator
- Page 452
-
The class example contains an error which might result in a
NullPointerException. The printArray() method
should be recoded as follows:
// Print the contents of an array
static void printArray(String[] a) {
for (int i = 0; i < a.length; i++) {
if (a[i] == null) {
System.out.println("(null)" + " ");
} else if (a[i].length() == 0) {
System.out.println("(empty)" + " ");
} else {
System.out.println(a[i] + " ");
}
}
}
DatagramSocket.DatagramSocket()
- Page 509
-
The last sentence of the second paragraph in the DESCRIPTION section is misleading.
It says that if localAddr is not specified, any address
associated with the local machine is used.
It should instead say that if localAddr is not specified,
the wildcard address 0.0.0.0 is used.
With the wildcard address, any outgoing packet will use
the platform-dependent default interface
(if the machine has more than one interface) and incoming packets
from any of the interfaces will be received by the socket.
getLocalAddress() and
getInterface() will return 0.0.0.0.
Also, the first paragraph in the DESCRIPTION section should contain the
clarification that if port is 0,
the new datagram socket is bound to any locally available port, and that
getLocalPort() will return the bound port, not 0.
DateFormat
- Page 583
-
The following section should be added to the class description:
Centuries and Year 2000 for Abbreviated Year
See SimpleDateFormat for how
a date string is parsed using the abbreviated year pattern "yy".
DateFormatSymbols
- Page 619, 620, 624
-
These four methods need the following note: getWeekdays(),
getShortWeekdays(), setWeekdays(), setShortWeekdays().
When accessing a weekday from the array, use the constants
Calendar.SUNDAY, Calendar,MONDAY
and so forth, rather than digits.
Deflater.DEFAULT_COMPRESSION
- Page 684
- The constant's value is -1 (not -11 as stated in
the book).
Deflater.Deflater()
- Page 686
- In the PARAMETERS section, lvl can have a
range of -1 to 9 (not 0 to 9 as stated in
the book).
Deflater.setLevel()
- Page 692
- In the PARAMETERS section, lvl can have a
range of -1 to 9 (not 0 to 9 as stated in
the book).
FileWriter constructor
- Page 832
- In the second paragraph of the DESCRIPTION section, change the
two occurrences of "file reader" to "file writer" (in the
descriptions of the third and fourth forms of the constructor).
FilterReader
- Page 848
-
The read(char[] b, int off, int len) method in the class example
is incorrect. Its definition should be as follows:
public int read(char[] b, int off, int len) throws IOException {
synchronized(lock) {
char[] tmp = new char[len+len];
int howmany = in.read(tmp);
int real_count = 0;
for (int i = 0; i < howmany; i += 2) {
b[off+real_count] = tmp[i];
real_count++;
}
return (real_count == 0? -1 : real_count);
}
}
GregorianCalendar
- Page 892
-
Delete "not" from the second sentence in the first paragraph of
the DESCRIPTION section of the GregorianCalendar
constructor so that the sentence reads:
-
-
The new instance is lenient.
InetAddress.equals()
- Page 958
-
Delete the last sentence of the DESCRIPTION section, and change
the second to last sentence to read as follows:
-
-
If a machine has multiple names but the same address, instances
of InetAddress for different names of that same machine
are equal.
Locale
- Page 1056, 1059
-
The RPC entry in Table 31 should read PRC instead.
Also, in the Locale class example, the line
print("RPC", Locale.PRC);
should be replaced witih
print("PRC", Locale.PRC);
Locale.equals()
- Page 1060
-
The EXAMPLE section should say: See clone().
Math.atan2()
- Page 1087
-
The second sentence in the DESCRIPTION section should read: This
method computes and returns the vectorial angle theta in the range
-pi to pi.
MessageFormat.format()
- Page 1112
-
In the DESCRIPTION section, the description about the third syntax is
incorrect. Although the third syntax form accepts an Object,
it is immediately cast into an Object[]. Therefore, the
third syntax form is identical to the second--that is,
singleArg is expected to be an Object[]. Use the
second form instead of the third form in all cases where you're using
a MessagFormat directly. The third form is only provided to
satisfy the corresponding abstract method declared in the
Format class.
In the PARAMETERS section, the description for
singleArg should say
The array of objects to be formatted
and inserted into the pattern.
The RETURNS section is missing. It should say:
A string formatted using the given arguments.
If arguments is null, the original pattern
is returned. If arguments contains null
objects, the formatted result will substitute each argument with the
string "null".
MessageFormat.parse()
- Page 1115
-
The last bullet should say:
- If a single argument is parsed more than once in the string, then
the latter parse wins.
MessageFormat.setFormat()
- Page 1119
-
variableNum - If out of range, an
ArrayIndexOutOfBoundsException is thrown.
MulticastSocket.MulticastSocket()
- Page 1159
-
The second paragraph in the DESCRIPTION section is incorrect.
It says that the multicast socket is bound to the address of any of the
available network interface on the local machine and that it can be changed
using setInterface().
In fact, the multicast socket is bound to the wildcard address (0.0.0.0).
With the wildcard address, any outgoing packet will use
the platform-dependent default interface
(if the machine has more than one interface) and incoming packets
from any of the interfaces will be received by the socket.
getLocalAddress() and
getInterface() will return 0.0.0.0.
setInterface() can be used to change the address of the
outgoing packets, but doing so will not change the address
to which the socket has been bound (i.e., the interfaces from
which it can receive incoming packets).
getInterface() will return the address set by setInterface(),
but the result of getLocalAddress() will not change.
NumberFormat.setMaximumFractionDigits()
- Page 1210-1212
-
These four methods are missing the following detail from the
newValue parameter description:
setMaximumFractionDigits(), setMaximumIntegerDigits(),
setMinimumFractionDigits(), setMinimumIntegerDigits()
newValue - If less than zero, then zero is used.
The concrete subclass may enforce an upper limit to this value
appropriate to the numeric type being formatted.
Object.notify()
- Page 1222
-
Add the following paragraph to the EXAMPLE section:
The example as shown is designed for a single
Retriever/Stacker pair.
If the program uses multiple Retriever and/or
Stacker threads, it must replace invocations of
notify() with notifyAll() in order to
avoid deadlocks.
OutputStreamWriter
- Page 1308
-
The first statement of the example in the Usage section has a right parenthesis
in the wrong place. It should read:
OutputStreamWriter out =
new OutputStreamWriter(new FileOutputStream("outputfile"), "UTF8");
Random.nextGaussian()
- Page 1400, 1404
-
Change the nextGaussian() entry in the MEMBER SUMMARY
on Page 1400, and the PURPOSE section of nextGaussian() on
Page 1404 to read:
Generates the next pseudorandom, Gaussian ("normally") distributed
double with mean 0.0 and standard deviation 1.0.
Replace the DESCRIPTION section with:
This pseudorandom sequence is generated by using the
polar method of G. E. P. Box, M. E. Muller, and
G. Marsaglia, as described by Donald E. Knuth in The Art of Computer
Programming, Volume 2: Seminumerical Algorithms, section 3.4.1,
subsection C, algorithm P.
Replace the RETURNS section with:
A pseudorandom, Gaussian ("normally") distributed double with
mean 0.0 and standard deviation 1.0 from this
random number generator's sequence.
Reader.read()
- Page 1431
-
In the RETURNS section, enumeration of the different forms is mixed up.
The first sentence should read:
"The second form returns the character read; the first and
third forms return the actual number of characters read."
Runtime
- Pages 1468, 1470, 1474, 1476
-
In the EXAMPLE sections of exec(), freeMemory(),
runFinalization(), traceInstructions(),
traceMethodCalls(),
add the following line before rt is used.
Runtime rt = Runtime.getRuntime();
Runtime.loadLibrary()
- Page 1473
-
The last sentence of the first paragraph in the DESCRIPTION section is incorrect.
It should instead say:
On Solaris, the library search path is specified by the environment
variable LD_LIBRARY_PATH.
On Windows, the library search order is as follows:
- The directory from which the application is loaded.
- The current directory.
- The "SYSTEM" directory (on NT, "SYSTEM32" first, then "SYSTEM")
- The "Windows" directory.
- The PATH environment variable.
SecurityManager.checkAwtEventQueueAccess()
- Page 1485
-
Delete the first paragraph in the DESCRIPTION section.
Serializable
- Page 1514
-
The Class1.java and Class2.java files were omitted
from the source listing, but they are included in the ZIP file of
examples that you can download from the FTP site.
They should be included on page 1514 of the book as follows:
public class Class1 implements Serializable {
int field1;
String field2;
transient int field3;
public Class1() {
field1 = 10;
field2 = "a string";
field3 = -1;
}
}
public class Class2 implements Serializable {
int field1;
String field2;
transient int field3;
public Class2() {
field1 = 10;
field2 = "a string";
field3 = -1;
}
private void writeObject(ObjectOutputStream out) throws IOException {
out.writeInt(field1);
out.writeUTF(field2);
}
private void readObject(ObjectInputStream in)
throws IOException, ClassNotFoundException {
field1 = in.readInt();
field2 = in.readUTF();
}
}
SimpleDateFormat
- Page 1542
-
The example in the result column for E and EEE should be "Tue" (not "Tues").
The full set of abbreviated days of the week for U.S. English are:
Sun, Mon, Tue, Wed, Thu, Fri, Sat. The full set of abbreviated months
of the year are: Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec.
The thirteenth month is the empty string.
- Page 1543
-
The following section should be added to the class description:
Centuries and Year 2000 for Abbreviated Year
When parsing a date string using the abbreviated year pattern "yy",
SimpleDateFormat must interpret the abbreviated year relative to some
century. It does this by adjusting dates to be within 80 years before
and 20 years after the time the SimpleDateFormat instance is created.
For example, using a pattern of "MM/dd/yy" and a SimpleDateFormat
instance created on Jan 1, 1997, the string "01/11/12" would be
interpreted as Jan 11, 2012 while the string "05/04/64" would be
interpreted as May 4, 1964.
SimpleTimeZone
- Pages 1559
-
The DESCRIPTION heading has an extraneous "1559" suffix that should be removed.
Socket.getLocalAddress()
- Pages 1579
-
The SYNTAX section should read
public InetAddress getLocalAddress()
Socket.getSoLinger(), Socket.setSoLinger()
- Pages 1581, 1583
-
The methods getSoLinger() and setSoLinger()
deal with time-out periods
in terms of seconds, not milliseconds as stated in the book.
Replace all occurrences of "milliseconds" with "seconds" in the
DESCRIPTION, RETURNS, and PARAMETERS sections of these two methods.
String.substring()
- Page 1651
-
Add the following sentence to the DESCRIPTION section:
"If endIndex has not been specified, it defaults to
length()."
StringCharacterIterator subrange
- Page 1672
-
For clarification, add this paragraph to the end of "Subrange":
Note that last() returns the last character in the
subrange, which is one character ahead of
setIndex(getEndIndex()).
System.in
- Page 1717
- The example is not portable because it assumes that \n
is the line terminator. The recommended way to read a line from
standard input, or any input stream, is to use BufferedReader.
Replace the example with the following:
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String str = in.readLine();
System.setOut()
- Page 1721
-
In the SYNTAX section, the argument to setOut() should be an
instance of PrintStream, not OutputStream.
Thread
- Page 1728
-
In the class example, the updateList() method
marks a thread that has not been interrupted as having
been interrupted and vice versa. The problem is that
the arguments to the t.isInterrupted() ? expression
are reversed.
Replace the t.isInterrupted() ? expression with:
(t.isInterrupted() ? "Interrupted" : "")
Thread.yield()
- Page 1749
-
In the example, replace synchronized (this) with
synchronized (Worker.class).
Throwable.getLocalizedMessage()
- Page 1771
-
In the SYNTAX section, the method name should be
getLocalizedMessage() instead of getMessage().
URL.getFile()
- Page 1809
-
In the method example, u.getFile() returns "/new.html",
not "new.html".
URLConnection.getHeaderField()
- Page 1835
-
In the EXAMPLE section, change
getHeaderField(2) to return "1224" (instead of "1223").
URLConnection.getHeaderFieldKey()
- Page 1836-1837
-
When a field has no key, null is returned, not an empty string as
stated in the book.
Change the third sentence to
Note that some fields have no key, in which case null is returned
(see example).
In the EXAMPLE section, change getHeaderField() to
getHeaderFieldKey().
Also, change getHeaderField(0) to return null
(instead of the empty string).
Writer.write()
- Page 1890
-
In the SYNTAX section, the char parameter in
the third method prototype is missing its array designation.
It should read:
public void write(char[] buf) throws IOException
ZipFile
- Page 1909
-
In the actionPerformed() method, delete the following line:
os.putNextENtry(new ZipEntry(ze.getName()));
ZipInputStream.getNextEntry()
- Page 1917
-
Delete the last sentence of the first paragraph in the DESCRIPTION section.
Contrary to what the sentence says,
if this ZIP input stream contains another ZIP file, it will be ignored.
Errata for First and Second Printing
BigInteger.compareTo()
- Page 111
-
In the sample code, replace usage of DataInputStream with
BufferedReader is = new BufferedReader(new InputStreamReader(System.in));
BigInteger.toString()
- Page 132
-
In the sample code, replace usage of DataInputStream with
BufferedReader is = new BufferedReader(new InputStreamReader(System.in));
Character.toTitleCase()
- Page 303
-
In the sample code, replace isSpace() with isWhiteSpace().
CheckedInputStream
- Page 336
-
In the class example, replace usage of DataInputStream with
BufferedReader is = new BufferedReader(new FileReader(args[0]));
Class.isAssignableFrom()
- Page 369
- Page 400
-
The Member Summary and PURPOSE section for isAssignableFrom() should read:
-
-
Determines if the class represented by this Class object
is a superclass of a class.
-
-
The second bullet in the DESCRIPTION section should read:
-
-
This Class object represents a class and is a superclass of cls.
ClassLoader.loadClass()
- Page424
-
Replace res with cl.getResource(args[2]).
Replace is with cl.getResourceAsStream(args[2]).
ContentHandlerFactory
- Page 491
-
In the class example, replace isLetterOrDigit(c) with
Character.isLetterOrDigit(c).
DecimalFormat
- Page 629
-
The list of patterns and formatted numbers in the upper half
of the page do not appear in columns as they should.
They should appear as follows:
Pattern Formatted Number
-#0.## -1234.56 // Prefix minus sign for negative value
-#0.# -1234.6 // 1 decimal place. Notice rounding up.
-#,##0.## -1,234.56 // Grouping separator for thousands
-00,000.000 -01,234.560 // Leading and trailing zero
-#### -1234 // No decimal places or decimal separator
(###0.#) (1234.5) // Parentheses to show negative value
###0.#- 1234.5- // Suffix minus sign
#,###% -123,456% // Percentage
- Page 630
-
(Table 23) In JDK 1.1.6, the symbol 'E' has been removed from
the set of special characters that can be used in
a subpattern. Therefore, avoid using it.
It has been included in JDK 1.2.
Modifier
- Page 1146
- In the class example, replace usage of DataInputStream with
BufferedReader is = new BufferedReader(new FileReader(args[0]));
Object.equals()
- Page 1217
- Add the following sentence to the second paragraph in the DESCRIPTION section:
-
If equals() is overridden, hashCode()
should also be overridden so that two objects that are
equal have the same hash code.
Object.hashCode()
- Page 1220
- Add the following sentence to the paragraph in the DESCRIPTION section:
-
If hashCode() is overridden, equals()
should also be overridden so that two objects that are
equal have the same hash code.
Object.notify()
- Page 1221
- Add the following sentences to the last paragraph in the DESCRIPTION section:
-
Furthermore, the thread does not release the monitor until
it exits the synchronized method/block from which notify()
is called, and consequently, the waiting thread being
notified cannot grab the monitor until that time.
In other words, the location of notify() within the
synchronized block is irrelevant.
PrintWriter
- Page 1356-1357
-
In the class example, place a try/catch clause around
the assignment of the out field. Change b.length
to buf.length.
SimpleDateFormat.parse()
- Page 1556
- Add '{' to end of the line for public static void main.
Socket.setSoTimeout()
- Page 1584
-
Change "server socket" to "socket" in the PURPOSE section.
String.lastIndexOf()
- Page 1644
-
Add to the DESCRIPTION section that if str is the empty string,
this.length() is returned. For example, "abc".lastIndexOf("")
returns 3.
StringBufferInputStream.available()
- Page 1667
- Because of a bug in the JDK,
StringReader.ready() always returns true
and therefore cannot be used as a replacement for
StringBufferInputStream.available().
System.setErr()
- Page 1720
-
In the sample code, use of the PrintStream constructors
are for illustrative purposes only, as usage of
these constructors are deprecated.
ZipFile
- Page 1907-1908
-
The description of the class example incorrectly references
a nonexistent example from Vector.setElementAt().
Instead, it should say that the example uses a variation of
the QuickSort class from the java.lang.reflect.Array
class example. This variation uses a Vector instead of
an array. Also, in the sample code, change Comparable to
Comparator.
ZipOutputStream
- Page 1930
-
In the class example, replace "OutputStream os" with "OutputStream out"
in the parameter list and in the code, replace the assignment to "os" with:
ZipOutputStream os = new ZipOutputStream(out);
-
Delete the extra closing parenthesis after calling
the NullOutputStream constructor.
This page was updated: 19-Mar-2002