The errata list is a list of errors and their corrections that were found after the product was released.
The following errata were submitted by our customers and have not yet been approved or disproved by the author or editor. They solely represent the opinion of the customer.
| Version |
Location |
Description |
Submitted By |
| Printed |
Page 3
graphic with source (#1) |
This code, once compiled, does not run. I get the error "Exception in thread "main" java.lang.NoSuchMethodError: main". I
am running jdk.1.6.0_02-b06 on Windows XP and all my environmental variables have been set. Should I be able to run this
code (see what I typed in below)?
=============================================
import java.awt.*;
import java.awt.event.*;
class Party {
public void buildInvite() {
Frame f = new Frame();
Label l = new Label("Party at Tim's");
Button b = new Button("You bet");
Button c = new Button("Shoot me");
Panel p = new Panel();
p.add(l);
}
}
===============================================
|
Anonymous |
| Printed |
Page 23
middle of page in class Test code |
Wrong way double-quotes in
System.out.print(x + "" + y + " ");
|
Anonymous |
| Printed |
Page 25
line 13 in "Code Magnets" solution |
this statement should appear after the second "if" branch.
x = x - 1;
System.out.print("-");
|
Anonymous |
| Printed |
Page 26
Left column (PoolPuzzleOne solution) |
Not an error, per se, but there is an alternate solution to the puzzle:
class PoolPuzzleOne {
public static void main(String[] args) {
int x = 0;
while (x < 4) {
System.out.print("a");
if (x < 1) {
System.out.print(" ");
}
System.out.print("n");
if (x < 1) {
System.out.print("oise");
x = x - 1;
}
if (x == 1) {
System.out.print("noys");
}
if (x > 1) {
System.out.print(" oyster");
}
System.out.println("");
x = x + 2;
}
}
}
|
Anonymous |
| Printed |
Page 26
Solution to Pool Puzzle One |
Not an error, exactly, but this seemed to work as well:
class PoolPuzzleOne {
public static void main(String [] args) {
int x = 0;
while (x<4) {
System.out.print("a");
if (x<1) {
System.out.print(" ");
}
System.out.print("n");
if (x<1) {
System.out.print("oise");
x=x-1;
}
if (x==1) {
System.out.print("noys");
}
if (x>1) {
System.out.print(" oyster");
}
System.out.println("");
x=x+2;
}
}
}
|
David |
| Printed |
Page 41
Third bullet point |
There is the common misconception of a blueprint once again.
Most believe that "blueprint" stands for the original when it is actually the opposite.
Original drawings where made on semi-transparent film (frosted film). When making copies to paper you use light-sensitive
paper the same size as the original. You place the original on top of the paper and insert into a giant exposure machine.
The result is a paper drawing with blue lines and blueish background.
So you see the blueprint is actually the instance object and not the class.
|
Anonymous |
| Printed |
Page 47
First Column, "Pool Puzzle" Solution, esp. lines 11 and 14 |
The error is one of omission:
While the solution is **a** possible solution to the puzzle, there are others. Lines
11 and 14 as printed read
if ( x == 3 ) {
and
if ( x < 0 ) {
Other solutions include
(A)
if ( x > 0 ) {
and
if ( x > 1 ) {
(B)
if ( x == 4 ) {
and
if ( x < 5 ) {
However, only (A) also solves the bonus question.
|
Anonymous |
| Printed |
Page 63
Compiler problem B |
The problem in the exercise is to find the code which will give compilation errors by
the compiler. However the problem B is fine for the compilation. The error mentioned
in the exercise solution, i.e the ArrayIndexOutOfBoundsException is a runtime
exception, which will never be caught by the compiler.
|
Anonymous |
| Printed |
Page 66
Tip |
In the 'Tip', the sentence that starts "Unless you're way smarter than us... it
mentions diagrams "like the ones on page 55 and 56 of this chapter".
remove "and 56"; it doesn't have any diagrams on it.
[and a minor note that I'm sure will be chuckled at.... the first sentence should be
"Unless you're way smarter than we are", not "us".
|
Anonymous |
| Printed |
Page 84
Last paragraph, bottom right of the page, next to the output window |
The paragraph "(Remeber, null just means [...]" misses the closing parenthesis.
|
Anonymous |
| Printed |
Page 91
Code of Puzzle4 of the Pool Puzzle Exercise |
The statement x=6; is superfluous. After the while loop, x is already 6.
|
Anonymous |
| Printed |
Page 92
4th paragraph |
Maybe not a mistake - a few phrases end with two dots ("it should.." and "your access modi.."), maybe there should be three.
|
Anonymous |
| Printed |
Page 93
Be the Compiler: Exercise B Solutions |
The "getTime()" and "setTime(String t)" methods in clas "Clock" are both private in the solutions. They should be public methods in order for class "ClockTestDrive" to have access to them.
|
Sarujan Kanapathipillai |
| Printed |
Page 106
output box in lower right corner |
The output of running "java SimpleDotComTestDrive" should read:
hit
passed
instead of just "hit"
|
Anonymous |
| Printed |
Page 110
method main, 8th statement in code |
Maybe not a mistake - since variable isAlive is a boolean I would write:
while(isAlive) {
instead of
while(isAlive == true) {
|
Anonymous |
| Printed |
Page 114
1st paragraph, last sentence. |
"you can just skim these last few pages..."
should be changed to:
"you can just skim these next few pages..."
|
Anonymous |
| Printed |
Page 115
Pre and Post Increment/Decrement Operator box |
"int x = 0; int z = ++x;
produces x is 1, z is 1"
should be:
"int x = 0; int z = ++x;
produces x is 0, z is 1"
Very similar mistake below that one as well.
|
Anonymous |
| Printed |
Page 149
checkUserGuess method |
The method includes the following for loop
for (DotCom dotComToTest : dotComsList) {
result = dotComToTest.checkYourself(userGuess);
if (result.equals("hit")) {
break;
}
if (result.equals("kill")) {
dotComsList.remove(dotComToTest);
}
}
When the program is run under JRE 1.5.0_04, the loop throws a
ConcurrentModificationException after the "dotComsList.remove(dotComToTest);"
statement is executed.
According to what I've been able to find, when using an ArrayList iterator (as the
for-each loop does), it is only legal to modify the ArrayList by using the iterator's
own remove or add methods
(From the JavaDoc for ConcurrentModificationException: "if a thread modifies a
collection directly while it is iterating over the collection with a fail-fast
iterator, the iterator will throw this exception.")
In order to avoid the exception the example code should use a standard for loop.
|
Anonymous |
| Printed |
Page 152
Third line of the placeDotCom method, slightly below the middle of the page. |
The line reads:
String [] alphacoords = new String [comSize]; // holds 'f6' type coords
The local string array "alphacoords" appears nowhere else in the placeDotCom method.
I suspect the comment regarding 'f6' coords belongs with the preceding line:
ArrayList<String> alphaCells = new ArrayList<String>();
|
Anonymous |
| Printed |
Page 153
Lines three through eight of the GameHelper code on the page. |
These six lines that test for a valid cell position:
if (location >= gridSize) { // out of bounds - 'bottom'
success = false; // failure
}if (x>0 && (location % gridLength==0)) { //out of bounds - right edge
success = false; // failure
}
are unnecessarily restrictive and therefore inefficient. Cells are often falsely
rejected. In order to not restructure the code any more than absolutely necessary
these six lines can be replaced by the following - admittedly complex - line.
// Disallow running off edge:
success = !((x < 3) && ((location >= gridSize) || ((incr == 1) && (location %
gridLength == 0))));
|
Anonymous |
| Printed |
Page 212
Inside command window depiction 2/3 of way down the page |
Dog sameDog = takeObjects(aDog);
should be:
Dog sameDog = getObject(aDog);
|
Anonymous |
| Printed |
Page 229
2nd paragraph of 'A'nswer on right side of page |
"... the compiler knows that its (should be 'it's') safe to cast anything that comes out of ArrayList do (should be 'to')
a dog reference."
|
Anonymous |
| Printed |
Page 231
Near the bottom of the page |
Very minor printing error?
For #4, there is a break in the arrow between the "Baz" and the "Bar"
classes. This line should be solid.
|
Anonymous |
| Printed |
Page 249
Answer to first "dumb question" |
The answer to the first question is missing "protected" which is a perfectly valid
access modifier for a constructor. (this should also reference appendix B).
|
Anonymous |
| Printed |
Page 250
2nd paragraph |
the sentence 'there is no other way to create an object other than someone, somewhere
saying new on the class type' is not correct - objects can also be created by
deserialization and cloning. Josh Bloch calls these 'pseudo-constructors' in
'Effective Java'.
|
Anonymous |
| Printed |
Page 254
The very last text line |
"*There's an exception to this rule; you'll learn it on page 252"
should read:
"*There's an exception to this rule; you'll learn it on page 256"
|
Anonymous |
| Printed |
Page 254
footnote on the bottom of the page |
Wrong page number stated in footnote. The footnote reads:
"* There's an exception to this rule; you'll learn it on page 252."
It should say "...on page 256."
|
Anonymous |
| Printed |
Page 266
Execise method "public static void doStuff2" |
The line "GC localGC" is incomplete. This will certainly have a compilation error.
|
Anonymous |
| Printed |
Page 269
Last but one paragraph, just after the code |
'...and a small smile creeped across his lips.' should be '...and a small smile crept across his lips.'
|
Anonymous |
| Printed |
Page 306
Key Calendar Methods graphic |
roll(int field, boolean up)
-- It might be clearer to use the other overloaded version of this method, namely:
roll(int field, int amount)
That's the one that was used on the previous page, i.e., "c.roll (c.DATE, 35);".
|
Anonymous |
| Printed |
Page 320
snapshot of MidiSystem class of the API docs |
It would be nicer if we can have the snapshot of API for Java 2 Platform SE 5.0,
instead of having Java 2 Platform SE v1.4.0) from the first edition.
|
Anonymous |
| Printed |
Page 323
Bottom of page (next to last line) |
Close parenthesis missing for the "catch block".
this code fragment should read:
public void crossFingers() {
try {
anObject.takeRisk();
} catch (BadException ex) {
System.out.println("Aaargh!");
}
}
Note the addition of the next-to-last close parenthesis...
|
Anonymous |
| Printed |
Page 342
nearly at the end of the code |
The code as it is does work, but after it is finished something stays active because the player is not stopped when finished.
This can be solved by inserting the following code between "player.start();" and "} catch ...":
long length = player.getTickLength();
Thread.sleep(length*200);
player.close();
This happens at least another time in a similar piece of code on another page.
|
Anonymous |
| Printed |
Page 354, 368
section of Making a GUI is easy and the EVENTS section of the Bullet |
Points page;
Java 5 has changed a way to add a component to a JFrame. And that could change the
code you have written for chapter 12 to chapter 15.
Java 1.4.x and earlier versions require that we have to add components to the frame's
content pane. But Java 5 doesn't require that.
So instead of writing:
frame.getContentPane().add(aJButton);
frame.getContentPane().add(aJPanel);
...
we could implicitly add a component to a frame without getting the content pane of
the frame:
frame.add(aJButton);
frame.add(aJPanel);
etc.
And if we're concerned about the compatibility issue, then it is safe to continue
using
frame.getContentPane.add(...);
|
Anonymous |
| Printed |
Page 362
Bottom of page "Sharpen your pencil" box, 2nd sentence |
Match the widgets with the events they might cause.
should be changed to:
Match the widgets with the event methods they might invoke.
or:
Match the widgets with the event listener callbacks they might invoke.
|
Anonymous |
| Printed |
Page 368
5th paragraph in righthand column |
graphics.setColor(Color.blue);
should be:
g.setColor(Color.blue);
|
Anonymous |
| Printed |
Page 370
Sharpen your pencil |
Refers to pictures on p351, should be p369.
|
Anonymous |
| Printed |
Page 371
Entire |
This code does not work on my system (Dual g5 Macosx10.4.3 with java5) It compiles
(begrudgingly: "failed to name mach port") and presents a window with circle and
button, but when I click on the button, it freezes and the console gives a host of
error that sum up to a NullPointerException at the line frame.repaint();
|
Anonymous |
| Printed |
Page 371
The bottom source code |
The comment in the paintComponent method of the MyDrawPanel refered to the wrong
page.
//See page 347 for the code
should read:
//See page 367 for the code
|
Anonymous |
| Printed |
Page 387
Right hand side bottom section |
Third bullet point is incorrectly labeled as bullet point 4.
|
Anonymous |
| Printed |
Page 389
Bottom of page |
Indentation of "makeEvent" method should match indentation of same method at the end
of the previous page (page 388).
|
Anonymous |
| Printed |
Page 391
MyDrawPanel line 18 |
g.fillRect is called with height and width reversed - should be:
g.fillRect(x, y, width, ht);
|
Anonymous |
| Printed |
Page 392
End of try block in go() |
Call to sequencer.setTempoInBPM(120) should probably be done before
sequencer.start().
|
Anonymous |
| Printed |
Page 392
just before halfway the code |
In the method setUpGui() I am missing the middle line of the next three lines:
f.setContentPane(m1);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setBounds(30, 30, 300, 300);
And near the end of the page I am missing
long length = (long) (sequencer.getMicrosecondLength()/1000);
Thread.sleep(length);
sequencer.close();
as well, between "sequencer.setTempoInBMP(120);" and "} catch...".
|
Anonymous |
| Printed |
Page 398
Pool Puzzle |
This is the answer for a pool puzzle, but the pool puzzle seems to be missing.
|
Anonymous |
| Printed |
Page 417
Constructor |
list = new JList(listEntries);
should be:
JList list = new JList(listEntries);
to remain consistent with the preceding pages
|
Anonymous |
| Printed |
Page 420
Middle of page, inside "main()" method |
new BeatBox2().buildGUI();
should be:
new BeatBox().buildGUI();
|
Anonymous |
| Printed |
Page 420
1st line in buildGui, 6th paragraph from the bottom of the page |
reads: theFrame = new JFrame("Cyber Beatbox");
Compiler rejects this. It works as:
JFrame theFrame = new JFrame("Cyber Beatbox");
|
Anonymous |
| Printed |
Page 420
halfway the code |
In the main method it says "new BeatBox2().buildGUI();". The "2" should not be there.
|
Anonymous |
| Printed |
Page 421
2nd paragraph |
When the program is run the labels don't line up with the checkboxes, and since the
program is using swing change the Label to JLabel.
Box nameBox = new Box(BoxLayout.Y_AXIS);
for (int i = 0; i < 16; i++) {
nameBox.add(new Label(instrumentNames[i]));
}
To make everything line-up you can change your code to this
GridLayout grid2 = new GridLayout(16,1);
grid2.setVgap(1);
grid2.setHgap(2);
JPanel mainPanel2 = new JPanel(grid2);
for (int i = 0; i < 16; i++) {
mainPanel2.add(new JLabel(instrumentNames[i]));
}// end loop
background.add(BorderLayout.EAST, buttonBox);
background.add(BorderLayout.WEST, mainPanel2);
|
Anonymous |
| Printed |
Page 421
BeatBox all versions at least through Ch 14 |
On my system: Windows Vista, Java 1.6.03, Java SE RE 1.6.03-b05, these programs do not release the CMD prompt on close.
I fixed it by adding:
abstract class MyExitListener implements WindowListener {
public void windowClosing(WindowEvent e) {
sequencer.stop();
}
}
as an inner class. Maybe there's a better way?
|
Anonymous |
| Printed |
Page 422
a little more than 1/3 of the way down |
JCheckBox jc = (JCheckBox) checkboxList.get(j + 16*i);
may be changed to:
JCheckBox jc = checkboxList.get(j + 16*i);
The "(JCheckBox)" cast is superfluous.
|
Anonymous |
| Printed |
Page 444
Bottom of page (command window depiction) |
The contents of the command window should be changed from:
% java GameSaver
Elf
Troll
Magician
to:
% java GameSaverTest
One's type: Elf
Two's type: Troll
Three's type: Magician
|
Anonymous |
| Printed |
Page 447
in the box in the upper-right corner |
after the comma between "bow" and "sword" the is a space, while there are no space after any of the other comma's.
|
Anonymous |
| Printed |
Page 448
QuizCard UML-like diagram, middle of page |
Format of UML-like diagram for QuizCard class has had no prior explanation of the
components and does not correspond to similar example on page 255 (which is also
presented without explanation).
|
Anonymous |
| Printed |
Page 448
Flash Card Image in the top right Corner |
The front of the flash card asks:
"What's the first
foreign country due
south of Detroit
Michigan?"
The corresponding Answer reads: "Canada (Ontario)"
Canada is *NORTH* of Detroit. So the question should read:
"What's the first
foreign country due
north of Detroit
Michigan?"
|
Anonymous |
| Printed |
Page 451
Middle of page, within highlighted box |
JFileChooser fileSave = new JFileChooser();
fileSave.showSaveDialog(frame);
saveFile(fileSave.getSelectedFile());
could potentially benefit from an added conditional test:
JFileChooser fileSave = new JFileChooser();
fileSave.showSaveDialog(frame);
if (fileSave.getSelectedFile() != null)
saveFile(fileSave.getSelectedFile());
This will prevent the java.lang.NullPointerException which results
from cancelling out of the file chooser dialog.
|
Anonymous |
| Printed |
Page 456
Instance variables in class QuizCardPlayer |
private JTextArea answer is declared but never used in the class.
|
Anonymous |
| Printed |
Page 471
Photo |
The phone has little bubbles coming out if it like it's going to say something, but
there's no thought bubble.
|
Anonymous |
| Printed |
Page 483
Paragraph labeled "3" under "How it works". |
Well, it's a serious technical mistake regarding TCP. It doesn't really affect the
Java that's used here.
"...the method returns a plain old Socket (on a different port)... The Socket is on a
different port than the ServerSocket, so that the ServerSocket can go back to waiting
for other clients"
That's not how TCP works. The Socket ends up with the same local port number as the
ServerSocket. A TCP connection is defined by the tuple of the client's IP and port
and the server's IP and port: it's the *combination* of those four items that
identifies a connection, so the server doesn't have to reserve the port for listening
purposes.
|
Anonymous |
| Printed |
Page 508
last few paragraphs |
The description of the problem doesn't match the output on the left side of the page.
It is implied that Monica drove the account negative, while the output indicates that it was Ryan that did so.
|
Anonymous |
| Printed |
Page 510
6th paragraph |
"So if you don't lock the back account"
should read
"So if you don't lock the bank account"
|
Anonymous |
| Printed |
Page 512
Paragraph beginning "The trick..." (and then the source code for TestSync) |
The text implies--at least this is my reading--that ++ is an atomic operation. It's
not.
An easy way to see this is to revise TestSync as follows: (1) in increment(), just do
balance++; (2) and then in run(), crank the upper bound on the for loop up (I just
started adding zeros and--on a Mac mini--started seeing funny results given a few
runs of the program with the upper bound at five million--er, with the print
statement moved down after the loop in run(), so it didn't take forever to run).
|
Anonymous |
| Printed |
Page 512
Whole page |
I'm confirming that "balance++" is not atomic, and here's why:
the corresponding assembly langugage (which is what is being run) is not.
Pegagogically, though, it may be helpful to represent this as 2 statements. But if you do, I suggest a note explaining that the ++ operator is not atomic.
|
Anonymous |
| Printed |
Page 531
middle |
The problem with
File file = new File("SongList.txt");
is twofold:
1- the file is not supplied in the OReilly zip folder
2- I created the file manually and saved it in the jukebox1 directory. Still I get a java.io.FileNotFoundException probably because of a path problem.
Thanks in advance for the correction.
|
Pierre Morel |
| Printed |
Page 549
2nd paragraph from the bottom |
The text in the book reads:
"A negative number (any negative number)
means the Song you were passed is greater then the Song
running the method. Returning a positive number says
that the Song running the method is greater then the Song
passed to the compareTo() method."
Those two sentences are easily confusable. Until I was looking at them
very closely to copy them here I thought they said the exact same thing.
I suggest either bolding thd differences or adding some sort of image
to help clarify the issue.
|
Anonymous |
| Printed |
Page 566
1st paragraph |
1st sentence:
... "how the object's should be sorted."
should be
... "how the objects should be sorted."
|
Anonymous |
| Printed |
Page 579
4th question |
The 4th box should be checked.
The statement
ArrayList<Dog> dogs = new ArrayList<Dog>();
does indeed compile...
|
Anonymous |
| Printed |
Page 579
Compiles? |
When I try compiling the examples in NetBeans v.6.0.1 using jdk1.5.0_12, I get a slightly different result regarding
which lines will compile.
In the example code below I've put an 'X' next to the lines that compile in my IDE.
....
import java.util.*;
import java.util.ArrayList;
public class GenericsTest {
public static void main(String[] args) {
ArrayList<Dog> dogs1 = new ArrayList<Animal>();
ArrayList<Animal> animals1 = new ArrayList<Dog>();
X List<Animal> list = new ArrayList<Animal>();
X ArrayList<Dog> dogs = new ArrayList<Dog>();
ArrayList<Animal> animals = dogs;
X List<Dog> dogList = dogs;
X ArrayList<Object> objects = new ArrayList<Object>();
X List<Object> objList = objects;
ArrayList<Object> objs = new ArrayList<Dog>();
}
}
abstract class Animal {
void eat() {
System.out.println("animal eating");
}
}
class Dog extends Animal {
void bark() {}
}
class Cat extends Animal {
void meow() {};
}
|
Anonymous |
| Printed |
Page 584
Last line on page - Running your code |
%java Mini
should read:
%java MyApp
|
Anonymous |
| Printed |
Page 585
Last bullet 3 |
%cd MiniProject/classes
should read:
%cd MyProject/classes
|
Anonymous |
| Printed |
Page 596
Inside Thought Bubble over illustration |
The text in the thought bubble appears to be missing a final word (and period) like
" release."
or
" version."
|
Anonymous |
| Printed |
Page 596
First Paragraph |
Sentence "The clients would always be up-to-date, and you'd never have to worry about delivering new" is unfinished.
|
B Hillebrecht |
| Printed |
Page 599
code |
"~kathy" should be removed from the "codebase=" line so that the following comment is
true: "This example shows that MyApp.jnlp is available in the root directory of the
web server ..."
|
Anonymous |
| Printed |
Page 602
Exercise 11 |
Exercise 11:
The corresponding answer to exercise 11 on page 604 indicates that 11 is "True".
Either the wording of this question could use clarification or this is incorrect as
it does not matter where the source file resides (absolute path to source file is
unrelated to the classes location in package hierarchy--you can put the source file
anywhere). Though it is a good idea/good practice to make them match as alluded to
at the bottom of page 589.
|
Anonymous |
| Printed |
Page 612
2nd sentence |
... "as though its calling a method"...
should be
... "as though it's calling a method"...
|
Anonymous |
| Printed |
Page 618
First Paragraph |
Printed: "It uses a naming convention that is the name of your remote implementation, with either _Stub or _Skeleton added to the end."
Correction: Printed: "It uses a naming convention that is the name of your remote implementation, with either _Stub or _Skel added to the end."
|
B Hillebrecht |
| Printed |
Page 619
bottom of the page in public static void main |
Naming.rebind("Remote Hello", service)
s/b
Naming.rebind("RemoteHello", service)
The space is not allowed - executing javac MyRemoteImpl with the space results in an
error. See also page 621, and remove the space from
Naming.lookup("rmi:127.0.0.1/Remote Hello");
|
Anonymous |
| Printed |
Page 674
Last sentence in 1st paragraph |
To be "state of the art," the Traverser's code would need to be Java 5, not Java 1.4.
|
Anonymous |