Errata

Learning Java

Errata for Learning Java

Submit your own errata for this product.

The errata list is a list of errors and their corrections that were found after the product was released. If the error was corrected in a later version or reprint the date of the correction will be displayed in the column titled "Date Corrected".

The following errata were submitted by our customers and approved as valid errors by the author or editor.

Color key: Serious technical mistake Minor technical mistake Language or formatting error Typo Question Note Update

Version Location Description Submitted By Date submitted Date corrected
Printed
Page 11
4th paragraph

The word 'runtime' is broken at the end of the line as 'runt-ime';
it should be broken 'run-time'

Anonymous   
Printed
Page 39
10th line from Bottom

A method or variable declared as private is only inaccessible from inside its own class.

NOW READS:
A method or variable declared as private is only accessible from inside its own class.

Anonymous    Feb 01, 2004
Printed
Page 43
1st and 3rd paragraphs

In the first paragraph, the line that says
'HelloJava2 newobj = new HelloComponent2("Hello Java!");

It should say
'HelloComponent2 newobj = new HelloComponent2("Hello Java!");'

There is a similar error in the third paragraph.

Anonymous   
Printed
Page 67
5th paragraph (just before "System Properties" heading)

Missing space before "method" in "The java interpreter continues to run until the
main()method of the initial class file returns..."

Anonymous   
Printed
Page 74
1st paragraph

If you really want the reader to follow these instructions, remove the "extends Bird"
and the "..." or the file won't compile.

Note from the Author or Editor:
Ok, it would be better to rework the text somehow (something got lost along the way) but for the reprint let's do as he suggests. Please remove the "extends Bird" from the line above.

Anonymous   
Printed
Page 77
output for "jar tvf spaceblaster.jar"

The first line of the output is incorrectly indented, so it doesn't line up with the other lines.

Anonymous   
Printed
Page 108
near top of page

There should be a semicolon (;) at the end of line for the following code sample

assert a > 0 : a
assert foo != null : "foo is not null!"

Anonymous   
Printed
Page 108
last 2 command line examples and last paragraph

The examples should have a class to execute. Instead of

% java -ea:com.oreilly.examples.Myclass

it should be

% java -ea:com.oreilly.examples.Myclass MyApplication

And instead of

% java -ea:com.oreilly.examples...

it should be

% java -ea:com.oreilly.examples... MyApplication

Also, there is a missing "a" before "package" in the last paragraph. Instead of "When
you enable assertions for package, Java also enables all subordinate package
names..." it should be "When you enable assertions for a package, Java also enables
all subordinate package names..."

Anonymous   
Printed
Page 108
near top of page

The assert statement throw an java.lang.AssertionError if the assert condition is
false.

The code sample

assert foo != null : "foo is not null!"

should read

assert foo != null : "foo is null!";
OR
assert foo != null : "foo cannot be null!";

Note from the Author or Editor:
Please change:

assert foo != null : "foo is not null!"

to:

assert foo != null : "Assertion failed: foo is null!"

Anonymous   
Printed
Page 109
middle of page

missing semicolon (;) at end of

doRight()

Anonymous   
Printed
Page 111
middle of the page, under "Array Types"

"An array of objects can be created in the same way:"

NOW READS:
"An array of objects can be declared in the same way:"

Anonymous    Feb 01, 2004
Printed
Page 119
3rd paragraph

The word "zero" is not a keyword or variable, so it shouldn't be set in monospace
font in "...it's given a default value appropriate for its type (null, zero, or false)."

Anonymous   
Printed
Page 130
4th paragraph

"We'll talk about method overriding later in the chapter."
should say:
"We'll talk about method overriding in the next chapter"

Anonymous   
Printed
Page 133
2nd to last paragraph

"The instance variable defaultDoors is not initialized until a later point in the
chain of constructor calls, ...."

NOW READS:
default_doors, not defaultDoors

Anonymous    Oct 01, 2003
Printed
Page 160
3rd paragraph

"the table doesn't addresses that scope"
should read
"the table doesn't address that scope"

Anonymous   
Printed
Page 187
code example

There are a number of bugs in the example:

-- method invoke() in interface InvocationHandler must be public and return Object

-- the variable interfaceName is never declared (you could use
method.getDeclaringClass().getName())

-- the Class.forName() call must be enclosed in a try block to catch
ClassNotFoundException

-- the array passed to newProxyInstance() should consist of "clas", the interface
class, not "class"

Note from the Author or Editor:
most of these are N/A as this is intended to be a snippet, however he is correct about this line:

clas. getClassLoader( ), new Class[] { class }, handler );

Please change to:

clas. getClassLoader( ), new Class[] { clas }, handler );

the "class" becomes "clas"

Anonymous   
Printed
Page 189
1st paragraph

"The magic is performed by slight of hand"

NOW READS:
"The magic is performed by sleight of hand"

Anonymous    Feb 01, 2004
Printed
Page 196
2nd paragraph

The text incorrectly refers to an instance method sleep(), when in truth there are only two static sleep() methods.

Anonymous   
Printed
Page 196
2nd paragraph

The third and fourth sentences of the second paragraph on p. 196 NOW READ as follows:

For this, we can use the static method Thread.sleep(), which affects
the currently executing thread. The call causes the thread to go idle
for a speciifed number of milliseconds:

Anonymous    Feb 01, 2004
Printed
Page 231
IN PRINT: 3rd paragraph, code sample

"String s = Integer.toHexString( 255 ).toUpper(); // s = "FF";"

NOW READS:
"String s = Integer.toHexString( 255 ).toUpperCase(); // s = "FF";"

Anonymous    Oct 01, 2003
Printed
Page 232
4th paragraph

(probably typo, but serious error anyway)
text:
You can retrieve the default Locale ... with the static Local.getDefault() method.
should be:
... with the static Locale.getDefault() method.

Anonymous   
Printed
Page 235
2nd para, first line of code

NOW READS:
double progress = 0.44;

Anonymous    Feb 01, 2004
Printed
Page 243
2nd Full Paragraph, email example

"w+@w+(.w)+" should probably read "w+@w+(.w+)+"

as it is written in the book, the expression only works if any dotted elements after
the first are only one character (user@mail.c or user@mail.a.b.c but not
user@mail.com)

Note from the Author or Editor:
I think this may be a duplicate, but true.

Anonymous   
Printed
Page 243
Before the section "Capture groups"

Incorrect regular expression to match email addresses

Printed:
\w+@\w+(\.\w)+ // Match an email address
Should be:
\w+@\w+(\.\w+)+ // Match an email address

As printed pat@pat.net, bob@foo.bar.com, and mate@foo.bar.co.uk would not match.

Note from the Author or Editor:
correct: Please change as indicated.

Anonymous  Mar 25, 2010 
Printed
Page 244
Alternation section - "parsing dates" example

w+, w+ d+ d+|dd/dd/dd //pattern 1 or pattern 2

should be:

w+, w+ d+ d+|dd/dd/dddd // pattern 1 or pattern 2

The text after the example states "In this expression, the left side matches patterns
such as Fri, Oct 12 2001, and the right matches 10/12/2001." Pattern 2 (the right
side) needs four digits (d) to match the year "2001".

Note from the Author or Editor:
Confirmed. It is on p. 331 of the Safari edition (not sure of the printed).

Please change the

\w+, \w+ \d+ \d+| \d\d/\d\d/\d\d // pattern 1 or pattern 2

to:

\w+, \w+ \d+ \d+| \d\d/\d\d/\d\d\d\d // pattern 1 or pattern 2

Anonymous   
Printed
Page 250
First example

The description and example of the String.split() method is wrong.
It's not static and therefore it also has a different argument list.

In the example code, the regex is also wrong. There are single backslashes where
there should be double.

The text says you can control whether you get empty strings, using an optional limit
field. That's not true. The limit field only limits the number of matches.

Note from the Author or Editor:
Two changes:

String [ ] fields = text. split( "\s*, \s*" ) ;

to:

String [ ] fields = text. split( "\\s*, \\s*" ) ;

and also from:

"yields a String array containing Foo, bar, and blah. You can control the maximum number of matches and also whether you get ?empty? strings (for text that might have appeared between two adjacent delimiters) using an optional limit field."

to:

"yields a String array containing Foo, bar, and blah. You can control the maximum number of matches and also whether you get ?empty? trailing strings using an optional limit field."

Anonymous   
Printed
Page 258
Table 10-4

In Table 10-4

nextFloat() returns a random float from 0.0 inclusive to 1.0 exclusive, not from -1.0
to 1.0 as listed

nextDouble() returns a random double from 0.0 inclusive to 1.0 exclusive, not from
-1.0 to 1.0 as listed

nextGaussian() should be clarified as returning a Gaussian distributed double value
with mean 0.0 and standard deviation 1.0. Only the standard deviation is mentioned,
and the type returned is not stated.

(At the top of page 259 the appropriate clarifications for nextGaussian() are made.)

Anonymous   
Printed
Page 264
Section Collections and Arrays, after second paragraph

The line:
String[] myStrings = (String[]) myCollection(new String[0]);
should be changed to:
String[] myStrings = (String[]) myCollection.toArray(new String[0]);

Note from the Author or Editor:
confirmed. Please change as shown.

Anonymous   
Printed
Page 304
last but one paragraph

"the Swing JFileDialog class"
should say:
"the Swing JFileChooser class"

Anonymous   
Printed
Page 304
Code sample following the 2nd paragraph

System.getProperty("user.dir"));

NOW READS:
System.getProperty("user.dir");

Anonymous    Oct 01, 2003
Printed
Page 305
2nd paragraph under File Options

"...getPath() returns the directory information without the filename."
should be:
"...getPath() returns the directory information and the filename."

Anonymous   
Printed
Page 306

Collections.sort(l);
should be
Collections.sort(list);

Anonymous   
Printed
Page 307
Table 11-1

The method for creating multiple directories in a path is written as Mkdirs(),
this should be lowercase, mkdirs().

Anonymous   
Printed
Page 309
Example under 4th paragraph

Example has:
FileInputStream fooOut = new FileOutputStream( ...
FileInputStream pwdOut = new FileOutputStream( ...

Should be
FileOutputStream fooOut = new FileOutPutStream( ...

etc.

Note from the Author or Editor:
p. 411

Please change:

FileInputStream fooOut =
new FileOutputStream( fooFile ) ; // overwrite fooFile
FileInputStream pwdOut =
new FileOutputStream( "/etc/passwd", true ) ; // append

to:

FileOutputStream fooOut =
new FileOutputStream( fooFile ) ; // overwrite fooFile
FileOutputStream pwdOut =
new FileOutputStream( "/etc/passwd", true ) ; // append

Anonymous   
Printed
Page 309
Beginning of 2nd paragraph

Missing space between words:
FileOutputStreamis

NOW READS:
FileOutputStream is

Anonymous    Oct 01, 2003
Printed
Page 311
4th paragraph

"In Chapter 11 we'll take a detailed look at building networked applications with
sockets."

NOW READS:
"In Chapter 12 we'll take a detailed look at building networked applications with
sockets."

Anonymous    Feb 01, 2004
Printed
Page 322
4th paragraph

The first sentence of paragraph 4:

"The position for reading and writing the Buffer is always greater than the mark,
which serves as a lower bound, and the limit, which serves as an upper bound."

NOW READS:
The position for reading and writing the Buffer is always between the
mark and the limit.

Anonymous    Oct 01, 2003
Printed
Page 323
Bottom of page

3rd line from end of page states:
(For example, shorts and floats consume two bytes each, longs and doubles four.)

NOW READS:
(For example, shorts are two bytes, floats are four, longs and doubles are eight.)

Anonymous    Oct 01, 2003
Printed
Page 343
2nd paragraph, 1st sentence

First sentence of paragraph under header "Do French web servers speak French?":
BufferedRead

NOW READS:
BufferedReader

Anonymous    Oct 01, 2003
Printed
Page 367
1st Paragraph starting with "Finally,"

The following HAS BEEN ADDED in the code section before the line starting with StringIterator:
public MyClient(String host) throws RemoteException {


Anonymous    Feb 01, 2004
Printed
Page 370
Third sentence in first paragraph

The text says that "Each call to select() returns the set of SelectionKeys that are
ready for some type of I/O'. This is incorrect. Instead, select() returns the number
of keys which are ready for some type of I/O. The selectedKeys() method returns the
Set of SelectionKeys that are ready for I/O.

Anonymous   
Printed
Page 374
8th line in write() method

The test to determine if the file has been completely read is incorrect. It should be
if (got == remaining)
rather than
if (got == -1 || remaining <= 0)

Anonymous   
Printed
Page 386

In the Post.java sample, in the line immediately following "// read:

results...";
The if statement immediately following the comment:
...
// read results...
if (urlcon.getResponseCode( ) != HttpURLConnection.HTTP_OK )
...
Based on the logic of the if statement, the test is backward;

NOW READS:
if (urlcon.getResponseCode( ) == HttpURLConnection.HTTP_OK )

Anonymous    Oct 01, 2003
Printed
Page 404
8th and 9th code lines from top of page

In the following two lines of code from the ShoppingCart.java sample:
out.println( "<html><head><title>Shopping Cart</title>"
+ "</title></head><body><p>" );

These code lines NOW READ:
out.println( "<html><head><title>Shopping Cart</title>"
+ "</head><body><p>" );

Anonymous    Feb 01, 2004
Printed
Page 405
Middle of the 3rd text paragraph

In line 6 of the 3rd paragraph:

... getValue() gives us a null array ...

This should say "getAttribute()", not "getValue()".

Anonymous   
Printed
Page 406
Next to last paragraph, last sentence

The text says "Indicating a negative time period is a good way to erase an existing
cookie of the same name". This is incorrect. Indicating a time period of 0 will erase
an existing cookie; indicating a negative time period will not affect existing
cookies of the same name.

Anonymous   
Printed
Page 439
3rd paragraph, 3rd sentence

The beginning of this sentence NOW READS:
"JFrame is derived from java.awt.Frame, which is ... "

Anonymous    Feb 01, 2004
Printed
Page 502
1st paragraph under "Validating Data"

Where it says
"Java 1.4 added the InputVerifier API"
it should say
"Java 1.3 added the InputVerifier API"
Sun's Javadocs and other resources mention that InputVerifier was added with 1.3.

Anonymous   
Printed
Page 506
Figure 17-4

The figure is from Microsoft Internet Explorer for Mac and not the CanisMinor Application.

Anonymous   
Printed
Page 682
2nd paragraph

The command
keytool -csr -alias Pat -file Pat.csr -keypass secure -storepass boofa

NOW READS:
keytool -certreq -alias Pat -file Pat.csr -keypass secure -storepass boofa

Anonymous    Oct 01, 2003
Printed
Page 692
Public Class SimpleElement

The public method
public void addText(String s) {...
should be
public void setText(String s) {...

Anonymous   
Printed
Page 694
public void characters() method

The public void characters() method uses .addText(text);

This should be .setText(text);

Anonymous