Bugs in multiple editions are denoted by page numbers p3/p2, p3/p2/p1
or p3//p1, where pn is the page number in the nth edition
- Page 31 6th line of note
- welcomeApplet.java should be welcomeapplet.java
- Page 41/39/38
- Change "For example, for WinEdit, chose Project|Compile, then
chose Project|Run." to "For example, for WinEdit, chose Project|Compile,
then chose Project|Execute."
- Page 43 line 8
- final t of WelcomeApplet is in the wrong font.
- Page 44
- Remove the sentence "(Note this used an older version ...)"
- Page 65/62/60
- Change int fourthBit to int fourthBitFromRight
.
- Page 71
- Change the description of String substring(int
beginIndex, int endIndex) to "Returns a string which is made
up of the part of the original string between beginIndex
(inclusive) and endIndex (exclusive)
- Page 76/81/80
- Several bugs have been reported with versions
of the Format class on the CD ROM:
- Formatting the most extreme negative number (-9223372036854775808L)
printed with 2 leading minus signs.
- Printing 0 with a %e or %g format did not work.
- Printing numbers that were closer to 1 than the number of
requested decimal places rounded down rather than up, e.g.
formatting 1.999 with %.2f printed 1.00. (This one is pretty
serious, of course.)
- Printing with precision 0 (e.g %10.0f) didn't work.
- Printing a string with a precision that exceeded the string
length (e.g. print "Hello" with %20.10s) caused a
StringIndexOutOfBounds error.
These are fixed in Format.java
- Page 78/69 Mortgage.java
- Code for mortgage calculator does not match
printed formula. Code should read: double payment = principal
* monthlyInterest / (1 - (1 / (Math.pow((1 + monthlyInterest), years
* 12))));
- Page 81
- Replace if {yourSales . . .
with if (yourSales . . . (2x)
- Page 84/74/72
- The second box of the graph should
read "balance = (balance+payment)*(1+interest)"
- Page 93/85/83
- Change "In our case, since
the method belongs to the lotteryOdds class" to "In our
case, since the method belongs to the LotteryOdds
class"
- Page 99
- ppublic ShellShort
should be public ShellSort
- Page 107
- Change "Since this
means an object may totally change how it stores its data but, as
long as it continues to use the same methods to manipulate the data,
no other object will know or care." to " This means an object
may totally change how it stores its data but, as long as it continues
to use the same methods to manipulate the data, no other object will
know or care."
- Page 120
- The example "
dueDate(1999,12,31);" should read "dueDate(1999,11,31);"
or "dueDate(1999,Calendar.DECEMBER,31);"
- Page 123/111/108
- Change: "Please
enter the month..." to "Please enter the month you were born, ..."
- Page 127
- Remove
public String getName()
{ return name;
}
- Page
129
- Change"this
class has five methods, whose headers look like this:" to "this class
has four methods, whose headers look like this:". Remove the
line public String getName().
- Page
130
-
Change "The new method is always used together with a constructor
to create the class" to "The new method is always used together
with a constructor to create an object of the class"
-
Page 132/119
-
"name - n;" should be "name = n;"
-
Page 132
-
Before the paragraph starting with "Of the remaining methods in this
class, the most interesting is the one that returns the year hired...",
add the following paragraph: "The raiseSalary method is
a function with two arguments. The first argument, called the
implicit argument is the object of type Employee that
appears before the method name. The second argument, the number inside
the parentheses after the method name, is an explicit argument
. As you can see, the explicit arguments are listed in the function
declaration. For example, double byPercent is explicitly
listed. The implicit parameter does not appear in the function
declaration."
-
Page 135
-
Replace "For example, consider a method compare..." with
"For example, consider a method equals..."
-
Page 138
-
Change "This way, all instances of the randomInteger class
can share this information" to "This way, all instances of the
RandomIntGenerator class can share this information"
-
Page 142
-
Change "For example, many Java classes have a method called toString()
that prints out the object." to "For example, many Java classes
have a method called toString() that returns a string
describing the object."
-
Page 142
-
Change "You can print out the current date stored in a date variable
by saying this.toString() . . . System.out.println("Customer.computeOverdue:
" + this)" to "If you pass any object to the System.out.println
method, that method invokes the toString method on the
object and prints the resulting string. Therefore, you can print
out the current state of the implicit argument of any method as
System.out.println(this);
-
Page 147
-
Replace
public int rank()
{ if (value == 1)
return 4 * 13 + suit;
else
return 4 * (value - 1) + suit;
}
with
public int rank()
{ if (value == ACE)
return 4 * 13 + suit;
else
return 4 * (value - 1) + suit;
}
-
Page 149
-
Change GregorianCalendar today = new java.util.GregorianCalendar();
to GregorianCalendar today = new GregorianCalendar();
-
Page 149/136/130
-
Reverse order of "c:\jdk\lib\corejava\Console.class" and "c:\jdk\lib\java\util\Console.class"
-
Page 150/136/130
-
".\jdk\util\Console.class" should be ".\java\util\Console.class"
-
Page 157, 159, ..., 203
-
The header line throughout the inheritance chapter is missing its
chapter number.
-
Page 159
-
Change "Now staff[1] and staff[2] each get a raise
of three percent because they are Employee objects."
to " Now staff[1] and staff[2] each get a raise
of five percent because they are Employee objects."
-
Page 159
-
Change "Example 5-1 is the full sample code that shows you the
Manager class at work." to "Example 5-1 shows you how objects
of the subclass Manager can be used in place of objects
of the superclass Employee ."
-
Page 161/147/143
-
Remove "We did that in the sample code of the preceding section".
-
Page 163
-
Change "Static binding depends on the method alone; dynamic binding
depends on the type of the object variable and the position
of the actual object in the inheritance hierarchy." to "Static binding
depends on the type of the object variable alone, dynamic
binding depends on the type of the actual object at run-time."
-
Page 163
-
Change "NOTE: Many Java users follow C++ terminology and refer to
virtual functions for functions that are dynamically bound."
to "NOTE: Many Java users follow C++ terminology and refer to functions
that are dynamically bound as virtual functions."
-
Page 165
-
Remove the sentence "Similarly, we needed to make a cast when we
used the Math.round method on a double (since round
returned a long)."
-
Page 166
-
Change "It is good programming practice to find out whether or not
your object is an instance of another object before doing a
cast." to " It is good programming practice to find out whether
or not your object is an instance of another class before
doing a cast."
-
Page 166
-
Change "The print and raiseSalary methods will
work correctly on both types because the dynamic binding that makes
polymorphism work locates the correct method automatically." to "The
raiseSalary method will work correctly on both types because
the dynamic binding that makes polymorphism work locates the correct
method automatically."
-
Page 168
-
Change "In Java, you use the abstract keyword to indicate
that a method cannot yet be specified in class." to "In Java, you
use the abstract keyword to indicate that a method cannot
yet be specified in this class."
-
Page 169
-
Change "iimport java.io.*;" to " import
java.io.*; "
-
Page 177
-
In the urlDecode method, change
ch = (char)(Format.atoi("0x"
+ in.substring(i, i + 2)));
i++;
to
ch = (char)(Format.atoi("0x"
+ in.substring(i, i + 2)));
i += 2;
-
Page 182
-
Change "Aside from asking an object for the name of its corresponding
class object, you can ask for the class object corresponding to a
string by using the static forName method." to "You can
obtain a Class object in two ways: by asking an object for
its corresponding class object, and by requesting the class object
corresponding to a string by using the static forName method."
-
Page 183
-
Change "Another example of a useful method is one that lets you create
an instance of a new class on the fly." to "Another example
of a useful method is one that lets you create an instance of a
class on the fly."
-
Page 186
-
Change "The program prompts you for the name of a class and then
writes out the signatures of all public methods and constructors
as well as the names of all public data fields of a class."
to "The program prompts you for the name of a class and then writes
out the signatures of all methods and constructors as well
as the names of all data fields of a class."
-
Page 187
-
In the printConstructors method, change String name =
cl.getName() to String name = c.getName().
-
Page 189
-
Change "Uses the methods in the Modifier class to
analyze the return value." to "Use the methods in the
Modifier class to analyze the return value."
-
Page 191
-
Replace
Field f = fields[i];
r += f.getName() + "=";
Object val = f.get(obj);
r += val.toString();
with
Field f = fields[i];
r += f.getName() + "=";
Object val = f.get(obj);
r += val.toString();
-
Page 193
-
Change "The point, as we mentioned earlier, is that a Java array
remembers the type of its entries, that iss the element type
used in the new expression that created it." to "The
point, as we mentioned earlier, is that a Java array remembers the type
of its entries, that is the element type used in the new
expression that created it."
-
Page 193
-
"To make this kind of generic array codes we need to be able" should
be "To make this kind of generic array copy we need to be
able"
-
Page 193
-
Change "To actually carry this outs we need to get the length
and component type" to "To actually carry this out we need
to get the length and component type"
-
Page 194
-
Replace
int[] ia = { 1, 2, 3, 4 };
ia = (int[])arrayGrow(a);
with
int[] ia = { 1, 2, 3, 4 };
ia = (int[])arrayGrow(ia);
-
Page 194
-
Replace
public static void main(String[] args)
{ ...
System.out.println("The following call will generate an exception.");
b = (Day[])badArrayGrow(b);
}
with
public static void main(String[] args)
{ ...
System.out.println("The following cast will generate an exception.");
b = (Day[])badArrayGrow(b);
}
-
Page 195
-
Change "To see method pointers at work, recall that you can inspect
or set a field of an object with the get method of the
Field class." to "To see method pointers at work,
recall that you can inspect a field of an object with the get
method of the Field class."
-
Page 195
-
Replace
Object invoke(Object obj, Object args[])
with
Object invoke(Object obj, Object[] args)
-
Page 196
-
Replace
Object[] args = { new Double(5.5); }
m2.invoke(harry, args);
with
Object[] args = { new Double(5.5)};
m2.invoke(harry, args);
-
Page 209/159/155
-
Change "For example, we wrote a Tile..." to "For example,
consider a Tile..."
-
Page 213
-
"You will read more about threads in Chapter 12" should be "See chapter
2 of volume 2 for more about threads".
-
Page 214/164/160
-
Change "So the //now what comment in..." to "So the
//now what? comment in..."
-
Page 218
-
Replace
Property carlsSalary = carl.getSalaryProperty();
double s = carlsSalary.get();
with
Property carlsSalary = carl.getSalaryProperty();
String s = carlsSalary.get();
-
Page 225
-
"No method except getSeniorityProperty has any knowledge of the getSeniorityProperty
class" should be "No method except getSeniorityProperty has any knowledge
of the SeniorityProperty class"
-
Page 233
-
Change "You will also see the basic methods for using the new
printings features of Java 1.1." to "You will also see the basic
methods for using the new printing features of Java 1.1."
-
Page 236 Example 7-1
-
The first line should be "import corejava.*;". The fourth line should
be "public class FirstFrame...". In the fifth line, there should
be a space between "String[]" and "args".
-
Page 240
-
Change setSize(Dimension d) to void setSize(Dimension
d).
-
Page 241
-
Code at bottom of page Frame f = new CloseableFrame() should
be Frame f = new NotHelloWorld1(),
-
Page 242
-
Change "from 75 pixels to the left" to "75 pixels to the right
"
-
Page 252
-
Change "The reason is that in some encoding schemes such as the Japanese
Shift-JIS code, some characters are encoded as single bytes, others
as multiple bytes, with "shift" characters switching between character
sets" to ""The reason is that in some encoding schemes such as the
Japanese JIS code, some characters are encoded as single bytes, others
as multiple bytes, with control codes switching between character
sets""
-
Page 254
-
Indent the first 18 lines of code in the sidebar by one tab stop
-
Page 254
-
Change
f.getColor(Color.pink);
f.drawString("Hello", 75, 100);
f.setColor(new Color(0, 128, 128)); // a dull blue-green
f.drawString("World", 75, 125);
to
g.getColor(Color.pink);
g.drawString("Hello", 75, 100);
g.setColor(new Color(0, 128, 128)); // a dull blue-green
g.drawString("World", 75, 125);
-
Page 258
-
Delete "(with one side missing because the drawPolygon function does
not close polygons)". (This was apparently a bug in the 1.0 AWT that
has been fixed in the 1.1 AWT.)
-
Page 268
-
Change "As you saw before, to get a Toolkit object, use the static
getDefaultToolkit method of the Toolkit class." to "To get a Toolkit
object, use the static getDefaultToolkit method of the Toolkit class."
-
Page 269 Example 7-11: Image1.java
-
You can remove the lines
import java.awt.image.*;
import java.net.*;
-
Page 270/211/207
-
"draws a scaled image" should be "draws an image".
-
Page 272
-
Add public to the update method as follows:
public void update(Graphics g)
-
Page 275
-
Change MediaTracker tracker = new MediaTracker(); to MediaTracker
tracker = new MediaTracker(this);
-
Page 281
-
The closing parenthesis in "by making a call to the getGraphics()
method" should be in Courier font
-
Page 282 Line 8
-
"pjpb" should be "pjob".
-
Page 287
-
Change getDimension to getPageDimension
(2x)
-
Page 291
-
Change "You can tell the compiler to issue a warning whenever you
use one of the older event handling methods..." to "You can tell
the compiler to flag all lines that use one of the older event handling
methods...
-
Page 301 last line
-
Change "having adapter class for these interfaces" to "having adapter
classes for these interfaces"
-
Page 302
-
Add public to the windowClosing method as follows:
class WindowCloser extends WindowAdapter
{ public void windowClosing(WindowEvent e)
. . .
-
Page 302
-
Change resize(300, 200) to setSize(300, 200)
-
Page 305
-
Replace
public class ButtonTest extends CloseableFrame
{ public ButtonTest ()
{ yellowButton = new Button("Yellow")
add(yellowButton);
. . .
}
. . .
private yellowButton;
}
with
public class ButtonTest extends CloseableFrame
{ public ButtonTest ()
{ yellowButton = new Button("Yellow");
add(yellowButton);
. . .
}
. . .
private Button yellowButton;
}
-
Page 307
-
"The flowing simple program extends the code above by letting..."
should be "The following simple program extends the code
above by letting..."
-
Page 307
-
Change "Note the key lines inside the loop inside the constructor"
to "Note the key lines inside the constructor"
-
Page 311 Table 8-1
-
In ComponentListener, add a row with the method componentShown
-
Page 311 Table 8-1
-
for FocusListener, under Parameter, "IsTemporary" should be "i
sTemporary"
-
Page 314
-
Change void lostFocus(FocusEvent evt) to void focusLost
(FocusEvent evt)
-
Page 315
-
Change "When the user pushes a key, a keyPressed KeyEvent
is generated. When the user releases the key, a keyRelease KeyEvent
is triggered." to "When the user pushes a key, a KEY_PRESSED
KeyEvent is generated. When the user releases the key, a
KEY_RELEASED KeyEvent is triggered."
-
Page 317
-
Embarrasingly enough, the book managed to attribute the wrong keystrokes
to vi cursor movement commands for three editions, incorrectly creating
the impression that the vi keys are arranged in a diamond-like fashion
that would aid memorization. Not so--the actual vi keys for cursor
movement are h, j, k and l, for left, down, up, and right. We'll
fix this in the next edition.
-
Page 322
-
Add g.dispose(); below g.drawString("Yikes", x, y);
.
-
Page 325
-
Change "The MouseEvent interface has five methods" to "The
MouseListener interface has five methods"
-
Page 325..327 MouseTest.java
-
Remove all three calls to g.translate(getInsets().left, getInsets().top);
-
Page 326 MouseTest.java
-
Change nsquares- (actually nsquares followed by a
dash) to nsquares--.
-
Page 331
-
Change "You can tell that an action originated from a menu by verifying,
with the instanceof operator, that the type of the event
source is a menu item using the instanceof operator." to
"You can tell that an action originated from a menu by verifying,
with the instanceof operator, that the type of the event
source is a menu item."
-
Page 335
-
Change
MenuItem mi1 = new MenuItem("Copy",
new MenuShortcut(KeyEvent.VK_C));
MenuItem mi2 = new MenuItem("Copy",
new MenuShortcut(KeyEvent.VK_LEFT));
to
MenuItem mil = new MenuItem("Cut",
new MenuShortcut(KeyEvent.VK_LEFT));
MenuItem mi2 = new MenuItem("Copy",
new MenuShortcut(KeyEvent.VK_C));
-
Page 331
-
Change "You can tell that an action originated from a menu by verifying,
with the instanceof operator, that the type of the event
source is a menu item using the instanceof operator." to
"You can tell that an action originated from a menu by verifying,
with the instanceof operator, that the type of the event
source is a menu item."
-
Page 339 MenuTest.java
-
Remove the two lines
else if (arg.equals("About"))
popup.show(this, 100, 100);
-
Page 341, 342 SeparateGUITest.java
-
- Add a call to repaint in the execute method
as follows:
public void execute()
{ target.setBackground(color);
target.repaint();
}
- The focus handling has been improved since the
book was printed, and now buttons actually retain keyboard focus.
Therefore, we must listen to them. In the frame constructor,
add the frame as a key listener to each of the three buttons,
like this:
b = new Button("Yellow");
b.addActionListener(yellowCommand);
b.addKeyListener(this);
add(b);
b = new Button("Blue");
b.addActionListener(blueCommand);
b.addKeyListener(this);
add(b);
b = new Button("Red");
b.addActionListener(redCommand);
b.addKeyListener(this);
add(b);
- addKeyListener(this); at the bottom of
SeparateGUITest() should be removed.
-
Page 344 MulticastTest.java
-
Change the main procedure as follows:
public static void main(String[] args)
{ Frame f = new MulticastTest();
f.show();
}
-
Page 348
-
In the code at the bottom of the page, before return p; add
a line g.dispose();
-
Page 349 EventQueueTest.java
-
This program has ceased to work with recent versions of the JDK. A
remedy would be to call the run method from the UI thread, not
the main thread. Here is a simple way to make that change. Change
the main method as follows:
public static void main(String[] args)
{ final EventQueueTest f = new EventQueueTest();
Button b = new Button("Draw Line");
f.add(b, "South");
b.addActionListener(new ActionListener()
{ public void actionPerformed(ActionEvent evt)
{ f.run();
}
});
f.show();
}
-
Page 354 CustomEventTest.java
-
Add g.dispose(); as the last line of the timeElapsed
method
-
Page 362/228
-
There should be a "Panels" heading just after the API notes.
-
Page 363
-
Change "The three buttons at the top of the screen..." to "The three
buttons at the bottom of the screen".
-
Page 365
-
Change public void reset() { minutes = 0; } to public
void reset() { minutes = 0; repaint(); }
-
Page 365
-
Change "...since it has both a class derived from Frame
and a class derived form Canvas" to "...since it has both
a class derived from Frame and a class derived from
Canvas"
-
Page 370 TextTest.java
-
Change Button b = new Button("Pack"); to Button b =
new Button("Tick");. In the listener below, remove the
two lines hourField.setColumns(10); and validate();
and instead add a line clock.tick();
-
Page 370 TextTest.java
-
The method textValueChanged has a reduntant pair of curly
braces.
-
Page 372
-
Change TextBox to TextField (1x) and
IntTextBox to IntTextField (2x)
-
Page 373
-
Change "See Example 9-3" to "See Example 9-4" and change "Example
9-4 shows" to "Example 9-3 shows"
-
Page 378
-
Remove the sentence "Only the text that is visible in the text area
will be printed."
-
Page 378
-
"Example 9-5: TextAreaText.java" should be "Example 9-5: TextAreaTe
st.java"
-
Page 379
-
The second constructor for TextArea should have 4 parameters:
TextArea(String text, int rows, int cols, int scrollBarLook)
After Parameters:. add "text the initial text".
-
Page 382
-
"Example 9-6: TextEditText.java" should be "Example 9-6: TextEditTe
st.java"
-
Page 384
-
The figure is incorrect. The text describes how the first check box
has focus, but the figure does not show the dotted rectangle around the
label that indicates focus.
-
Page 390
-
The line p.setLayout(new FlowLayout()); is not necessary.
-
Page 410 ScrollPaneTest.java
-
Remove private Scrollbar horiz; and private Scrollbar
vert;
-
Page 410 ScrollPaneTest.java
-
Change void main(String args[]) to void main(String[]
args)
-
Page 418
-
Change "The top area is a panel containing a row of buttons that
make the different cards show up in the top area. " to "The top area
is a panel containing a row of buttons that make the different cards
show up in the bottom area. "
-
Page 420 CardLayout.java
-
In actionPerformed, change else layout.show(cards, (String)arg);
to else layout.show(cards, arg);. The cast is unnecessary
since the variable arg is already a string.
-
Page 422/267/263
-
Replace new GridLayout(5,4) with new GridLayout(4,4)
-
Page 427
-
Change "In the grid bag layout for Figure 9-19, we set the ... "
to "In the grid bag layout for Figure 9-20, we set the ... "
-
Page 431
-
panel.add(OK); should be panel.add(ok);
-
Page 433 CircleLayoutTest.java
-
Change void main(String args[]) to void main(String[]
args)
-
Page 433/278/274 CircleLayoutTest.java
-
Change maxComponentHeight = Math.max(maxComponentWidth, d.height)
to maxComponentHeight = Math.max(maxComponentHeight,
d.height).
-
Page 434 CircleLayoutTest.java
-
Change
c.setBounds(x - d.width / 2, y - d.width / 2,
d.width, d.height);
to
c.setBounds(x - d.width / 2, y - d.height / 2,
d.width, d.height);
-
Page 439 PrintComponentTest.java
-
In the paint method of SavingsCanvas, remove the
line double scale = d.height / maxValue; The variable scale
is not used anywhere in the program.
-
Page 441/281/277
-
Replace "You will need to tell it the name of" with "You will need
to supply a reference to".
-
Page 446
-
The book has the DataExchangeTest program from the second edition,
and the correct program is missing on the CD ROM. The correct version is
in DataExchangeTest.java
-
Page 458
-
Change "Example 9-22: ImageButton.java" to "Example 9-22: ImageButton
Test.java"
-
Page 471/326/322
-
In step 3, append "and import the java.applet package"
-
Page 492
-
Change "TIF or JPEG" to "GIF or JPEG
-
Page 503
-
Change "...but we would need to manually repeat this search process
to located the associated resource file" to "...but we would need
to manually repeat this search process to locate the associated
resource file"
-
Page 535/387/383
-
"you should define the hashValue method" should be "you
should define the hashCode method"
-
Page 539
-
In the sample table output, change CLASSPATH=.;c:\\jdk\\lib
to CLASSPATH=c:\\jdk\\lib;c:\\CoreJavaBook;.
-
Page 560
-
Change
public int size() { data.size(); }
public Enumeration elements() { data.elements(); }
to
public int size() { return data.size(); }
public Enumeration elements() { return data.elements(); }
-
Page 575
-
In figure 12-1, all arrows must be reversed!
-
EmployeeSortTest.java (CD only)
-
{ return 1900 + hireDate.getYear(); should read { return
hireDate.getYear();