Errata


Print Print Icon

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 "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



Version Location Description Submitted By Corrected
Printed Page xiii
(This change was made to the 12/98 reprint but please note this

information if you have a previous printing of the book.)

Under the section "Java Example Online," add the following section regarding
licensing information:

Licensing Information

You may study, use, modify, and distribute these examples
for any non-commercial purpose, as long as the copyright
notice at the top of each example is retained. If you would
like to use the code in a commercial product, you may purchase
a commercial use license from the author for a nominal fee.
Visit http://www.davidflanagan.com/javaexamples/ for information
on obtaining such a license.

Please note that the examples are provided as-is, with no
warranty of any kind.

Anonymous 
Printed Page xiii
1st para.: the correct URL for the examples is

http://www.oreilly.com/catalog/9781565923713

Anonymous  Apr 1998
Printed Page index
now starts on page 369 and has been

rerun to reflect the removal of the appendix

Anonymous  Dec 1998
Printed Page 1
last paragraph, second sentence: changed "They" to "There"

Anonymous  Apr 1998
Printed Page 1

The last paragraph did read :

"There were referring, of course"
now reads
"They were referring, of course"

Anonymous  Apr 2000
Printed Page 6
Example 1-3: lines 8 and 9

int current, prev=1, prevprev=0; // Initialize some variables
for(int i = 0; i < 20; i++) { // Loop exactly 20 times

now reads

int current, prev=1, prevprev=1; // Initialize some variables
System.out.print("1 1 "); // Output the initial two values
for(int i = 2; i < 20; i++) { // Loop, outputting remaining values

and in the paragraph above, in line 5
"First, it again uses a for statement to loop 20 times."
now reads
"First, it again uses a for statement as its main loop."

Anonymous  Apr 2000
Printed Page 10
paragraph 2, line 4:

"So, in this examples" should be "So, in this example".

Anonymous 
Printed Page 10
Example 1-8

if (x == 1) return 1;

now reads:

if (x <= 1) return 1;

Anonymous  Dec 1998
Printed Page 16
Example 1-13

line 24, changed
if (c >= 'Z' ) c -= 26;
to
if (c > 'Z' ) c -= 26;

and line 28, changed
if (c >= 'z' ) c -= 26;
to
if (c > 'z' ) c -= 26;

Anonymous  May 1998
Printed Page 16
Example 1-13

line 24, changed
if (c >= 'Z' ) c -= 26;
to
if (c > 'Z' ) c -= 26;

and line 28, changed
if (c >= 'z' ) c -= 26;
to
if (c > 'z' ) c -= 26;

Anonymous  Jun 1998
Printed Page 19
line 3:

"interatively" should be "interactively".

Anonymous 
Printed Page 24

The end of example 2-4 now reads:

public void draw(Graphics g) {
g.setColor(fill);
g.fillRect(x1, y1, (x2 - x1), (y2 - y1));
g.setColor(border);
g.drawRect(x1, y1, (x2 - x1), (y2 - y1));
}

Anonymous  Apr 1998
Printed Page 27
Example 2-6

line 8, changed
int seed = 1;
to
long seed = 1;

line 13, changed
public Randomizer(int seed) { this.seed = seed; }
to
public Randomizer(long seed) { this.seed = seed; }

and line 36, changed

Randomizer r= new Randomizer((int)new java.util.Date().getTime());

to

Randomizer r= new Randomizer(new java.util.Date().getTime());

Anonymous  May 1998
Printed Page 27
Example 2-6

line 8, changed
int seed = 1;
to
long seed = 1;

line 13, changed
public Randomizer(int seed) { this.seed = seed; }
to
public Randomizer(long seed) { this.seed = seed; }

and line 36, changed
Randomizer r= new Randomizer((int)new java.util.Date().getTime());
to
Randomizer r= new Randomizer(new java.util.Date().getTime());

Anonymous  Jun 1998
Printed Page 27
Example 2-6, lines 32-33

inserted the word "the" between "and specified"

Anonymous  Dec 1998
Printed Page 41
Example 3-1: Added a closing " to the class-comment for "Hello

World!"

Anonymous  Apr 1998
Printed Page 42
second last line

font = new Font("Helvetica", Font.BOLD, 48);

changed "Helvetica" to "sansserif"

Anonymous  Apr 1998
Printed Page 71
second paragraph. 4th sentence: changed "to created" to "to

create"

Anonymous  Apr 1998
Printed Page 84
Example 5-1, lines 1-2: changed

import java.applet.*; import
java.awt.*;
to
import java.applet.*;
import java.awt.*;

Anonymous  May 1998
Printed Page 84
Example 5-1, lines 1-2: changed

import java.applet.*; import
java.awt.*;
to
import java.applet.*;
import java.awt.*;

Anonymous  Jun 1998
Printed Page 90
1st para., line 2: changed "use it structure" to "use it to

structure"

Anonymous  Apr 1998
Printed Page 93
second last paragraph, line 1: changed "The adaptor class..." to

"The adapter class..."

Anonymous  Apr 1998
Printed Page 97
Example 5-7, line 4

* and keyboard events. This is a required or events won't be sent.

should read

* and keyboard events. This is required or events won't be sent.

Anonymous 
Printed Page 99
example 5-9, line 5: changed "all the event" to "all the events"

Anonymous  Apr 1998
Printed Page 114
Example 6-5, replaced code with new code

import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class CardLayoutExample2 extends Applet {
public void init() {
// Create a layout manager, and save a reference to it for future use.
// This CardLayout leaves 10 pixels margins around the component.
final CardLayout cardlayout = new CardLayout(10, 10);
// Specify the layout manager for the applet
this.setLayout(cardlayout);
// Create a listener to invoke the next() method of cardlayout.
ActionListener listener = new ActionListener() {
public void actionPerformed(ActionEvent e) { // When button is clicked
cardlayout.next(CardLayoutExample2.this); // display the next one.
}
};
for(int i = 1; i <= 9; i++) {
Button b = new Button("Button #" + i);
b.addActionListener(listener);
this.add("Button" + i, b); // Specify a name for each component
}
}
}

Anonymous  Dec 1998
Printed Page 114
The line

cardlayout.next(CardLayoutExample2.this);
now reads
cardlayout.next(CardLayoutExample.this);

Anonymous  Apr 2000
Printed Page 118
Example 6-7, line 10: changed

b.setBounds(i*26, i*18, 100, 25); // use reshape() in Java 1.1
to
b.setBounds(i*26, i*18, 100, 25); // use reshape() in Java 1.0

Anonymous  May 1998
Printed Page 118
Example 6-7, line 10: changed

b.setBounds(i*26, i*18, 100, 25); // use reshape() in Java 1.1
to
b.setBounds(i*26, i*18, 100, 25); // use reshape() in Java 1.0

Anonymous  Jun 1998
Printed Page 118
Example 6-8, header comments

*margin_height -- how much space...left and right
*margin_width -- how much space...top and bottom

now reads

*margin_height -- how much space...top and bottom
*margin_width -- how much space...left and right

Anonymous  Dec 1998
Printed Page 124
paragraph 1, line 1:

An important features of the Frame class ...

should read

An important feature of the Frame class ...

Anonymous 
Printed Page 131
Example 6-13, changed the following line

Frame f = new Frame("InfoDialog Test");
To:
Frame f = new Frame("YesNoDialog Test");

Anonymous  Dec 1998
Printed Page 139
under exercise 6-1, in the last sentence, changed "more" to

"move"

Anonymous  Apr 1998
Printed Page 158
Changed the line

// Ask whether to overwrite it
System.out.print("Overwrite existing file " + to_name + "? (Y/N): ");

To:

// Ask whether to overwrite it
System.out.print("Overwrite existing file " + to_file.getName() +
"? (Y/N): ");

Since this adds a line, we removed the blank line
(to keep current page breaks) before:

// If the destination is a directory, use the source file name

Anonymous  Dec 1998
Printed Page 161
FileViewer.java, in method setFile:

The program went into infinite loop when reading Japanese file.

File f;
FileReader in = null;

try {
f = new File(directory, filename); // Create a file object
in = new FileReader(f); // Create a char stream to read it

int size = (int) f.length(); // Check file size
// This size is the file size in byte. ------(1)

char[] data = new char[size]; // Allocate an array big enough for it
int chars_read = 0; // How many chars read so far?
while(chars_read < size) // Loop until we've read it all
chars_read += in.read(data, chars_read, size-chars_read);
// chars_read is total read size in unicode char ------(2)

textarea.setText(new String(data)); // Display chars in TextArea
this.setTitle("FileViewer: " + filename); // Set the window title
}

The author's response: This is an embarrassing mistake, and I am grateful to
you for noticing it. In general, I have difficulty catching
internationalization errors like this since I do not have a system that uses
or can display Japanese text. (And even if I did, I could not develop
meaningful examples, since I have no comprehension of the language...)

Of the two solutions you propose, I prefer the first one. We should show an
example that is guaranteed to work in all cases. However, to improve the
efficiency, I would recommend that you modify the example to read more than
one line at a time. You use a BufferedReader, which makes reading individual
lines efficient, but I fear that appending individual lines to the TextArea is
not efficient. So I propose code like this:

f = new File(directory, filename); // Create a file object
in = new FileReader(f); // Create a char stream to read it
char[] buffer = new char[4096];
int len;

while((len = in.read(buffer)) != -1) {
String s = new String(buffer, 0, len);
textarea.append(s);
}

Note that I have not tested this code, with English text or with Japanese
text. I'm just trying to give you an idea of what I'm suggesting. I think
this code is properly internationalized, and should always work. If it does
not, go ahead and use the code you proposed.

Anonymous 
Printed Page 163
paragraph 2, line 6:

"it creates and display a FileViewer window" should be "it creates and
displays a FileViewer window".

Anonymous 
Printed Page 191
Example 9-4, changed the following line

to_server.println("GET " + filename);

to:

to_server.println("GET " + filename + "
");

Anonymous  Dec 1998
Printed Page 197
Example 9-7, line 7

* This applet uses the connects to the ...
now reads
* This applet connects to the ...

Anonymous  Apr 2000
Printed Page 238
second text paragraph, changed

"manifest.stub" to "manifest" (keep in italics)

Also, changed the following line:

Name: oreilly/beans/MultiLineLabel.class
To:
Name: oreilly/beans/yesno/MultiLineLabel.class

Finally, changed the following line:

% jar cfm MultiLineLabel.jar manifest.stub
oreilly/beans/MultiLineLabel.class
To:

% jar cfm MultiLineLabel.jar manifest
oreilly/beans/yesno/MultiLineLabel.class

Anonymous  Dec 1998
Printed Page 258
Example 12-1, line 18

else if (c.getModifiers() != null)
now reads
else if (c.getSuperclass() != null)

Anonymous  Apr 2000
Printed Page 266
and (267) changed the following line

String filename = f.getFile(); // Get the user's response

To:

String filename = f.getDirectory() + f.getFile(); // Get response

Anonymous  Dec 1998
Printed Page 274
Example 14-1, removed the following line

import java.applet.*;

Anonymous  Dec 1998
Printed Page 296
para. 1, line 2-3:

... the 4.XX "RemoteBank interface" RemoteBank interface ...
now reads
... the RemoteBank interface ...

Anonymous  Apr 2000
Printed Page 304
Example 15-4 removed the line: "import Mud.*;"

Anonymous  Dec 1998
Printed Page 304
para. 1, line 1:

Example 15-4 s.XX "remote method invocation(RMI)" "MudServer class"
hows the ...
now reads
Example 15-4 shows the ...

Anonymous  Apr 2000
Printed Page 307
Example 15-5 same change

Anonymous  Dec 1998
Printed Page 314
Example 15-6 same change

Anonymous  Dec 1998
Printed Page 315
Example 15-7 same change

Anonymous  Dec 1998
Printed Page 328
Example 16-1, lines 27-28: changed

status = s.getMoreResults();
} while(status || s.getUpdateCount() != -1);
to
status = s.getMoreResults();
// With some buggy JDBC drivers, this condition causes an infinite
// loop with SQL updates. If that happens, change to: while(status);
} while(status || s.getUpdateCount() != -1);

(removed blanks lines between lines 10 and 11 and between lines 24 and
25 to preserve the page breaks.)

Anonymous  May 1998
Printed Page 328
Example 16-1, lines 27-28: changed

status = s.getMoreResults();
} while(status || s.getUpdateCount() != -1);
to
status = s.getMoreResults();
// With some buggy JDBC drivers, this condition causes an infinite
// loop with SQL updates. If that happens, change to: while(status);
} while(status || s.getUpdateCount() != -1);

(removed blanks lines between lines 10 and 11 and between lines 24 and 25
to preserve the page breaks.)

Anonymous  Jun 1998
Printed Page 330
After the line "Object value = rs.getObject(i+1);", added the line

if (value != null)

and changed indentation of the next line so the code now reads:

Object value = rs.getObject(i+1);
if (value != null)
overwrite(line, colpos[i] + 1, value.toString().trim());

(Don't change the indent of the second "overwrite" line.)

Finally, since we added a line, we cut the blank line before:

// Finally, end the table with one last divider line

(appendix) completely removed

Anonymous  Dec 1998
Printed Page 381
Example 6, line 10 from the bottom: changed

// Add some items to the Edit menu
to
// Add some items to the View menu

Anonymous  May 1998
Printed Page 381
Example 6, line 10 from the bottom: changed

// Add some items to the Edit menu
to
// Add some items to the View menu

Anonymous  Jun 1998