Welcome to the Core Java Bug List
Third (1.1) Edition Bugs
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
Volume 1
- 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();
Volume 2
-
Page 5
-
Arrows are missing from ObjectInputStream to InputStream
and from ObjectOutputStream to OutputStream
-
Page 5
-
Change the classes deriving from DeflaterOutputStream from
GZIPInputStream and ZipInputStream to GZIPOut
putStream and ZipOutputStream
-
Page 6
-
Change the class deriving from OutputStreamWriter from
FilterWriter to FileWriter
-
Page 7
-
Change "That is, we can only read bytes and byte arrays from the
object in" to "That is, we can only read bytes and byte
arrays from the object fin".
-
Page 16
-
Replace
OutputStreamWriter out = new OutputStreamReader(new
FileOutputStream("output.txt"));
with
OutputStreamWriter out = new OutputStreamWriter(new
FileOutputStream("output.txt"));
-
Page 21
-
Change "Also creates a new PrintWriter from an existing
OutputStream but allows you determine whether the writer
autoflushes or not." to "Also creates a new PrintWriter
from an existing OutputStream but allows you to determine
whether the writer autoflushes or not."
-
Page 26
-
In the code sample, lines 2 and 5 are indented too far
-
Page 26
-
In the code sample, change send data to ze to send
data to zout
-
Page 46
-
API note header "java.io.ObjectInputStream" is missing.
-
Page 64
-
Change ".. then there is no problem with reading the object new data."
to "... then there is no problem with reading the new object
data."
-
Page 75
-
Change "Programs that can run more than thread at once are said to
be multithreaded." to " Programs that can run more than
one thread at once are said to be multithreaded."
-
Page 90
-
Change "MAX_PRIORTY" to "MAX_PRIORITY"
-
Page 112
-
Change "Transfer $9600 to from Account 1 to Account 2" to "Transfer
$9600 from Account 1 to Account 2"
-
Page 147
-
Change "The other important method you need is showDocument,
which we also discussed in the applet chapter in Volume 1." to "The
other important method you need is openStream, which we also
discussed in the applet chapter in Volume 1."
-
Page 200
-
Change "The JDBC manager will try to find a driver than can
use the protocol specified in the database URL by iterating through
the available drivers currently registered with the device manager."
to "The JDBC manager will try to find a driver that can use
the protocol specified in the database URL by iterating through the
available drivers currently registered with the device manager.".
-
Page233
-
Change "We indicate where make these changes. " to "We indicate where
to make these changes.".
-
Page 247 and 250
-
Change clear to reset
-
Page 258
-
Change "...you will see this technique in Chapter 7." to ""...you
will see this technique in Chapter 6."
-
Page 260
-
In the last bullet, do not set "Stubs" as Courier.
-
Page 268
-
Change "if the target system doesn't support high color" to "if the
target system doesn't support the "true" color model"
-
Page 272
-
Change "The x, y parameters specify the top left corner for the cropped
image, and the width and height parameters specify how large and
image to crop." to "The x, y parameters specify the top left corner
for the cropped image, and the width and height parameters specify
how large an image to crop.".
-
Page 279
-
Add bullet point before the "SINGLEFRAME" paragraph.
-
Page 315
-
Change "We will not do work that here" to "We will not do
that work here".
-
Page 344
-
Change "add two "Explicit" beans" to "add two "ExplicitButton
" beans".
-
Page 351
-
Change "through a propertyChange event" to "through a
PropertyChange event"
-
Page 352
-
Change filename to fileName (in item 2 and in figure
7-14).
-
Page 355
-
Change "..., which allows the the compiler to not have to
second_guess the programmer's intentions by analyzing method names."
to "..., which allows the compiler to not have to second_guess
the programmer's intentions by analyzing method names.".
-
Page 355
-
Change public bool isPropertyName() to public
boolean isPropertyName()
-
Page 360
-
Change "If a boolean property is changed, then an Integer
is returned" to "If a boolean property is changed, then
a Boolean is returned"
-
Page 387
-
Change "int p = ((Integer)getValue()).intValue();" to "
int i = ((Integer)getValue()).intValue();"
-
Page 387
-
Change "wrapper object" to "wrapper object" (2x). (I.e. don't
set as Courier)
-
Page 399 API note for getJavaInitializationString
-
Change "...that can be used to enerate code..." to "...that can be
used to generate code..."
-
Page 437 ClassLoaderTest.java
-
In the loadClassBytes method of the CryptoClassLoader
class, make the following two changes: Change
String cname = name.replace('.', '/') + ".class"
to
String cname = name.replace('.', '/') + ".caesar"
and change
buffer.write(ch);
to
buffer.write(ch - key);
-
Page 445
-
The code listing for Example 8-3 shows the code for CipherTest.java
and not the one for VerifierTest.java,which it should show.
-
Page 451, 454 SecurityManagerTest.java
-
Change getClassContext()[0] == getClassContext()[i] to
cc[0] == cc[i].
-
Page 454 SecurityManagerTest.java
-
Change String[] badWords = { "sex", "drugs", "C++" }; to
String[] badWords = { "sex", "drugs", "c++" };. (Note: The
checkRead method turns the input word into lowercase before
looking it up.)
-
Page 466
-
Change "What Tom does is use his private key..." to "What Joe
does is use his private key..."
-
Page 484
-
(last line) Change "cay@horstmann.com.x509" to "cay.x509
"
-
Page 494
-
The FileReadApplet.java's source is missing from the CD.
-
Page 516
-
Change Local germanSwitzerland to Locale germanSwitzerland
-
Page 559
-
In ProgramResources_de, change getObject to handleG
etObject and add { . . . } around the if/else/else
statement.
-
Page 560
-
In ProgramResources_en_US, change getObject to
handleGetObject and add { . . . } around the
if/else/else statement.
Second Edition Bugs
Bugs in both editions are denoted by page numbers p2/p1, where p2 is the
page number in the second edition and p1 the page number in the first
edition.
-
Page 6
-
Change http://www.cs.princeton.edu/~felton to http://www.cs.princeton.edu/
sip. The link http://ferret.lmh.ox.ac.uk/~david/java/bugs/ is
no longer available.
-
Page 7
-
Change http://java.sun.com:80/java.sun.com/sfaq/index.html to http://java.sun.com/sfaq/index.html
-
Page 9
-
First paragraph: "third-part" should be "third-party"
-
25
-
'Go to \WIN95NT\WINEDITA' should be 'Go to \WIN95NT\WINEDIT\WINEDITA'.
-
Page 25
-
There is no separate doc directory. The documentation for
RMI and JDBC has been integrated into the class tree. There is no api
directory either. JavaSoft didn't want us to distribute it. The
same information is available, in more convenient from, in the class
tree extracted with javadoc.
-
Page 29/29
-
Change java welcomeapplet.java to javac welcomeapplet.java
.
-
Page 52
-
Eliminate: "In fact, comments do not nest in Java." This should be
a note at the end of the "Comments" section, as it was in the first
edition.
-
Page 74/72
-
The "A" in "A while loop tests at the top" should not be
in the Courier font.
-
Page 106/104
-
Date.parse returns a long, not a void (the
number of milliseconds since 1/1/70 00:00 GMT).
-
Page 112/109
-
Change "we check the month (d.month())" to "we check the
month (d.getMonth())"
-
Page 118
-
A constructor is always called with the new keyword." newshould
be in Courier font.
-
Page 171/167
-
Change "Probably the most commonly used method of getClass"
to "Probably the most commonly used method of the class Class
"
-
Page 193
-
Replace int cy = client_height / 2 with int cy = client_height
/ 2 + in.top and replace g.drawRect(0, 0, client_width -
1, client_height - 1) with g.drawRect(in.left, in.top, client_width
- 1, client_height - 1)
-
Page 223
-
Change the call to setTitle to setTitle("ButtonTest");
(without spaces or :)
-
Page 229/225
-
Change setTitle("Panel test") to setTitle("PanelTest")
-
Page 234
-
TextTest.java is missing code: setTitle("TextTest");.
-
Page 258
-
In figure 7-11, remove the arrows TextComponent -> ScrollBar ->
List to Label -> Choice -> Checkbox -> Canvas -> Button.
(This bug won't die--it was fixed in the second printing of the first
edition, but it reemerged in the second edition.)
-
Page 280/277
-
Replace "before beginning to the read operation." with "before beginning
the read operation.".
-
Page 283/279
-
Replace both occurrences of "else . . ." with "else
if . . ."
-
Page 287/283
-
change "in the processResults method" to "in the processResult
method"
-
Page 293/289
-
Replace "(between 0 and 32)" with "(between 0 and 31)".
-
Page 303/299
-
Both the method mouseMove() and mouseDrag() are
missing a return true statement.
-
Page 303/299
-
In mouseDrag, replace draw(current) with draw(g,
current) (2x)
-
Page 313/309
-
The code right below the first and second paragraph, replace vert.setValue(horiz.getValue(),
d.height, 0, 400); with vert.setValues(vert.getValue(),
d.height, 0, 400);
-
Page 321/317
-
public void paint(graphics g)
Font f = new Font("System", Font.BOLD, 18);
{ ...
should be
public void paint(graphics g)
{ Font f = new Font("System", Font.BOLD, 18);
...
-
Page 327/323
-
The CalculatorApplet.java program doesn't include the import corejava.*,
awt.*, and applet.* statements
-
Page 328/324
-
For the calculator applet, since the calculator doesn't have a %
button, the line in the calculate method
else if (op == "%") ...
is not needed.
-
Page 357/353
-
In Example 8-5: CrawlerApplet.java, in the method "search", the line
"AppletContext context = getAppletContext();" should be removed
-
Page 376/372
-
Replace Item i = (Item)itemsOrdered.removeElementAt(n);with
itemsOrdered.removeElementAt(n); (The method has no return
value.)
-
Page 381/377
-
Change String s = "149-16-2536" to String s = "987-98-9996"
-
Page 381
-
The line e = staff.get(s); // gets harry should read e
= (Employee)staff.get(s); // gets harry.
-
Page 410/404
-
Change "The first four options are not appropriate" to "The first
three options are not appropriate"
-
Page 410/404
-
Change "But if the List class is part of the default package"
to "But if the LinkedList class is part of the default
package"
-
Page 414/408
-
The computation of the future values had the year and the interest
rate swapped. Replace balance[i][j] = futureValue(10000, 10 + 10 *
i, 5 + 0.5 * j); with balance[i][j] = futureValue(10000,
5 + 0.5 * j, 10 + 10 * i); . The correct values of the table
are then:
5.00% 5.50% 6.00% 6.50% 7.00% 7.50%
10 16470.09 17310.76 18193.97 19121.84 20096.61 21120.65
20 27126.40 29966.26 33102.04 36564.47 40387.39 44608.17
30 44677.44 51873.88 60225.75 69917.98 81164.97 94215.34
40 73584.17 89797.65 109574.54 133696.02 163114.11 198988.89
50 121193.83 155446.59 199359.55 255651.37 327804.14 420277.39
Jay Freedman, the discoverer of this bug, writes: "Interestingly, the
results of the erroneous version are similar to (at least, the same
order of magnitude as) those from the correct version. Beware of output
that 'looks' correct!"
-
Page 458
-
Change "or 1 to skip a number of bytes" to "or one to skip a number
of bytes"
-
Page 535/531
-
The program should use notifyAll instead of notify.
-
Page 546/542
-
Change g.drawImage(image, -i * imageHeight, imageCount, null)
with g.drawImage(image, 0, -i * imageHeight / imageCount,
null)
-
Page 546/542-543
-
In the class definition(s) of Animation, replace extends
Runnable with implements Runnable
-
Page 556/552
-
Sun has turned off port 13 on java.sun.com; try time-A.timefreq.bldrdoc.gov
instead.
-
Page 565
-
Remove "public" from the front of "class ThreadedEchoHandler"
-
Page 566/562
-
Replace "client'(space)s" with "client's" and replace "Let'(line
break)s" with "Let's
-
Page 575/571
-
Change os.writeBytes to out.writeBytes (2x)
-
Page 592
-
Change San Jose to San+Jose
-
Page 613
-
There should be a comma after NUMERIC(m, n). The or
should not be set in Courier (2 x).
-
Page 635
-
The line
ResultSet rs = md.getTables("", null, "%", types)
should be changed to
ResultSet rs = md.getTables(null, "%", "%", types)
to be consistent with the sample program. Actually, these parameters
depend somewhat on your SQL server.
-
Page 656
-
Change the URL from "" to "rmi://" with the 1.1
Beta version of RMI.
-
Page 688
-
The files HelloNative.h and HelloNative.c are switched.
First Edition Bugs
-
Page 24*
-
Replace SET CLASSPATH=C:\java\lib;C:\CoreJavaBook with
SET CLASSPATH=C:\java\lib;.;C:\CoreJavaBook
-
Page 25
-
At the end of second paragraph, add "Use the File | OpenFile command
and select the file tree.html in the \java\api directory."
-
Page 36*
-
Replace Void Main with void main to match the figures
-
Page 39
-
Remove import java.net.*;
-
Page 39
-
Replace method "action" with
public boolean action(Event evt, Object arg)
{ if (arg.equals("Open"))
{ FileDialog d = new FileDialog(this,
"Open image file", FileDialog.LOAD);
d.setFile("*.gif");
d.setDirectory(lastDir);
d.show();
String f = d.getFile();
lastDir = d.getDirectory();
if (f != null)
image = Toolkit.getDefaultToolkit().getImage(lastDir + f);
repaint();
}
else if(arg.equals("Exit")) System.exit(0);
else return false;
return true;
}
where lastDir is a private variable of ImageViewer.
-
Page 48
-
Replace \CoreJavaBook\ch2\FirstSample directory. with \CoreJavaBook\ch3\FirstSample
directory.
-
Page 49
-
Replace "Thus you must have a main method (function) for your code
to compile." with "Thus you must have a main method (function) for
your code to execute."
-
Page 53
-
Replace "(7 significant decimal digits)" with "(6-7 significant decimal
digits)"
-
Page 59*
-
Replace 3 !==7 with 3 != 7
-
Page 60*
-
Replace int thirdBit = (foo&8)/8: with int thirdBit
= (foo&8)/8;
-
Page 60
-
Replace "gives you a one if the third bit in the binary representation
of foo is on," with "gives you a one if the fourth bit from the right
in the binary representation of foo is on,"
-
Page 62*
-
Replace Expletive: with Expletive;
-
Page 62
-
Replace string greeting = "Hello"; with String greeting
= "Hello";
-
Page 62
-
Replace string s = greeting.substring(0, 4) with String
s = greeting.substring(0, 4);
-
Page 63
-
Replace int n = greeting.length() // is 5. with int n
= greeting.length(); // is 5.
-
Page 66*
-
Before "Once you have done this...", add
Be sure to add the line
import corejava.*;
to every program that utilizes the Console class.
-
Page 66*
-
Add the line import corejava.*; before the line class
...
-
Page 67*
-
Add the line import corejava.*; before the line class
...
-
Page 67*
-
Replace "Your payment is" with "Your payment is "
-
Page 70
-
The code should read
if (yourSales >= 2*target)
{ performance = "Excellent";
bonus = 1000;
}
else if (yourSales >= 1.5*target)
{ performance = "Fine";
bonus = 500;
}
else if (yourSales >= target)
{ performance = "Satisfactory";
bonus = 100;
}
else
{ System.out.println("You're fired");
}
-
Page 71
-
Remove C++ note. At the bottom of page 60, add
Selection Operator
The expression
condition ? e1 : e2
evaluates to e1 if the condition is true, to e2 otherwise. For example,
x < y ? x : y
computes the smaller of x and y.
-
Page 71*
-
Add the line import corejava.*; before the line class
...
-
Page 73*
-
Add the line import corejava.*; before the line class
...
-
Page 75*
-
Add the line import corejava.*; before the line class
...
-
Page 76
-
missing ; after Console.readInt()
-
Page 80
-
The Format class on the CD ROM has a bug--formatting 9.999 with "%.2f"
shows up as 9.00. This is fixed in Format.java
-
Page 80*
-
At the end of the sidebar, add
You must add the line
import corejava.*;
to every program that uses the Format class.
-
Page 82*
-
Add the line import corejava.*; before the line class
...
-
Page 88*
-
Add the line import corejava.*; before the line class
...
-
Page 100
-
Replace (Benjamin Cumming, 1994). with (Benjamin Cummings,
1994).
-
Page 101
-
At the end of 13th line(Now you can start applying AudioClip methods
to meow), add "(Actually, it is a little harder in Java to obtain a
real audio clip. Here we just use audio clips to introduce the typical
object notation.)"
-
Page 103
-
Replace Date preMillenium = new Date(1999,12,31); with
Date preMillennium = new Date(99,11,31);
-
Page 103
-
Replace Date preMillenium = new Date(1999,12,31,23,59,59);
with Date preMillennium = new Date(99,11,31,23,59,59);
-
Page 105
-
Add the line import java.util.*; before the line class
...
-
Page 106
-
There is a bug on the CD ROM in the default constructor of the Day
class. Here is the correct Day.java
.
-
Page 108*
-
Replace Date with Day
-
Page 109*
-
Replace "make a Date object" with "make a Day object"
-
Page 111
-
Replace { return name with { return name;
-
Page 113*
-
Replace "there are actually five access levels" with "There are actually
four access levels". (Note: The private protected attribute
is being withdrawn.)
-
Page 113
-
The instance fields in "Next, notice that there are three
instance fields" should be set in italics.
-
Page 115
-
Replace { return name with { return name;
-
Page 116
-
Replace "By the way, the function is called getName() because
it can't be called name()-" with "We could actually call
the method name(), although it would be confusing to have
a variable and a method that are called the same."
-
Page 119
-
Replace javac Mortgage with java Mortgage
-
Page 120
-
Remove package corejava;
-
Page 121
-
Replace Date today = new Date() with Day today = new
Day()
-
Page 121
-
Replace Date preMillenium = new Date(1999,12,31) with Day
preMillenium = new Day(1999,12,31)
-
Page 125
-
At the bottom of this page, replace int cards; with private
int cards;
-
Page 126
-
Replace the code final public void fill() with the code at
the bottom of this page
-
Page 143
-
In the third paragraph, replace "However, staff[0] "forgets"
that it refers to a Manager and just considers itself as
Employee object." with "However, staff[0] is only considered
to be an Employee object by the compiler."
-
Page 148*
-
Replace "Java uses the inheritance syntax" with "Java uses the cast
syntax"
-
Page 148
-
Replace Manager* boss = dynamic_cast<Manager>(staff[1]);
with Manager* boss = dynamic_cast<Manager*>(staff[1]);
-
Page 159
-
Replace public string powerSource(PoweredVehicle); with
public String powerSource(PoweredVehicle);
-
Page 162
-
After the first paragraph, add "Tip: Instead of writing x.toString()
, you can write "" + x. That expression concatenates
the empty string "" with the string representation of x, that
is, x.toString(). This trick is a common idiom that you find in many
java programs."
-
Page 172*
-
Remove the two sentences "To placate the C++ crowd... the same package".
-
Page 172*
-
Add a "C++ Note" icon to the paragraph that starts with "As it happens,
protected..."
-
Page 172*
-
Remove "3. visible to the class and all subclasses" and renumber
the remaining lines
-
Page 177
-
The second line in the second paragraph, replace "Alternative Window
Toolkit or AWT. Even though it is called the "alternative" toolkit,
you don't have ..." with "Abstract Window Toolkit or AWT. At one
point, it was called the "alternative" window toolkit, but you don't
have ... "
-
Page 182
-
Replace "How you handle an event is controlled by the handleEvent
method in the Event class." with "How you handle an
event is controlled by the handleEvent method in the Component
class."
-
Page 183
-
Replace "you need to override the paint method from the
Frame class" with "you need to override the paint method
from the Component class"
-
Page 184
-
In the second paragraph, replace "Not a Hello, World" with "Not a
Hello, World program"
-
Page 184
-
On the first line, replace "they are" with "it is"
-
Page 186
-
Replace Font(String name, Font property, int size) with
Font(String name, int property, int size)
-
Page 187
-
Replace cy += fim.stringWidth(s2); with cx += fim.stringWidth(s2);
-
Page 195
-
Replace int angle = 30;; with int angle = 30;
-
Page 195
-
Replace // opening angle of mouth with // half the opening
angle of mouth
-
Page 197
-
Replace void draw3dRect(...) with void draw3DRect(...)
-
Page 200
-
Add the following to the bottom of this page: "For the alternating
rule, a point is inside if an infinite ray with the point as origin
crosses the path an odd number of times."
-
Page 201
-
Replace int angle = 30;; // opening angle of mouth with
int angle = 30; // half the opening angle of mouth
-
Page 204*
-
Replace Toolkit.getDefaultToolkit.getImage(name) with Toolkit.getDefaultToolkit
().getImage(name)
-
Page 206
-
Replace "The tiling occurs in the paint program." with "The tiling
occurs in the paint method."
-
Page 209
-
In the method paint, replace buffered_image with //
buffered_image
-
Page 209
-
On the top of the page, repalce for(int j = 0; j <= client_width
/ image_width; j++) with for(int j = 0; j <= client_height
/ image_height; j++)
-
Page 209
-
Replace "updates the component without erasing the current image."
with "updates the component unless overridden, it erases the screen
area and calls the paint method."
-
Page 210
-
Align text following dx and dy parameters
-
Page 212*
-
Replace "Since Frame (indirectly) extends" with "Since
Frame indirectly implements"
-
Page 214
-
replace java.awt.ImageObserver with java.awt.image.ImageObserver
-
Page 218
-
Figure 7-1 has wrong button labels. Figure 7-2 on page 221 has wrong
button labels too
-
Page 219
-
Replace yellowButton.setBackground(color.yellow); with
yellowButton.setBackground(Color.yellow);
-
Page 221
-
Replace note on this page with "The add method belongs to the panel,
not the layout manager. But the layout manager needs to know about
the added items, and, more importantly, the layout directives (such
as "North"). It needs that information so it can do the layout. Thus,
whenever you add an item to a container, the container passes on
the item and any layout directives to the layout manager."
-
Page 223
-
In the method "action", replace else return false; with
else return super.action(evt, arg);
-
Page 227
-
In the method "action", replace else return false; with
else return super.action(evt, arg);
-
Page 231
-
Replace int hours = Integer.parselnt(hourField.getText().trim())
with int hours = Integer.parseInt(hourField.getText().trim())
-
Page 231
-
In the method "action", replace else return false; with
else return super.action(evt, arg);
-
Page 235
-
Replace the method "getValue()" with
public int getValue()
{ int value;
try
{ value = Integer.valueOf(getText().trim()).intValue();
}
catch(NumberFormatException e)
{ value = 0;
}
return value;
}
-
Page 243
-
Replace Panel p; with
Panel p = new Panel();
p.setLayout(new FlowLayout());
-
Page 250
-
In the second paragraph, replace "parameters that take the number
of items ..." with "a parameter that takes the number of items ..."
-
Page 254*
-
Remove the arrows TextComponent -> ScrollBar -> List to Label ->
Choice -> Checkbox -> Canvas -> Button
-
Page 254
-
Replace panel.addLayout(new CardLayout()); with panel.setLayout(new
CardLayout());
-
Page 260
-
Replace 'and "Dialog".' with 'and "Preferences".'
-
Page 260
-
Replace
{ if(arg.equals("<"))
layout.next(cards));
else if ...
}
with
{ if(arg.equals("<"))
layout.previous(cards));
else if ...
}
-
Page 262
-
In the class SimpleDialog, remove
Panel p = new Panel();
p.add(new Button("OK"));
add("south", p);
-
Page 264
-
Add line import corejava.*; after the first line
-
page 265
-
Replace
if (op == "+") arg += n;
else if (op == "-") arg -= n;
else if (op == "*") arg *= n;
else if (op == "/") arg /= n;
else if (op == "%") arg %= n;
else if (op == "=") arg = n;
with
if (op.equals("+")) arg += n;
else if (op.equals("-")) arg -= n;
else if (op.equals("*")) arg *= n;
else if (op.equals("/")) arg /= n;
else if (op.equals("%")) arg %= n;
else if (op.equals("=")) arg = n;
-
Page 266
-
The text beneath figure 7-17, replace "the list box spans three columns,"
with "the list box spans three rows,"
-
Page 266
-
The text beneath figure 7-17, replace "and the text field at the
bottom spans three fields." with "and the text field at the bottom
spans three columns."
-
Page 267
-
The second line from the end, replace "then the area never grows
beyond its initial size in that direction." with "then the area never
grows or shrinks beyond its initial size in that direction."
-
Page 269*
-
The program has a glitch in the constructor. It also doesn't actually
show the font in the sample line. The file
FontDialog.java
fixes these blemishes.
-
Page 270
-
At the bottom of this page, replace int weightx, weighty
with double weightx, weighty
-
Page 270
-
Replace add(sample, gbl, gbc, 0, 3, 4, 1); with add(sample,
gbl, gbc, 0, 3, 3, 1);
-
Page 271
-
Add panel.add(ok); in front of the last line
-
Page 275
-
Remove if(n == 0) return;
-
Page 278
-
Replace if(arg.equals("OK")) dispose(); with if(arg.equals("Ok"))
dispose();
-
Page 280
-
In method "handleEvent", replace System.exit(0); with
dispose();
-
Page 282
-
Replace if(arg.equals("OK") with if(arg.equals("Ok")
-
Page 282
-
The first line, replace ConnectInfo defaults = new UserInfo(defaultName,
""); with ConnectInfo defaults = new ConnectInfo(defaultName,
"");
-
Page 287
-
The top part of this page should read
FileDialog d = new FileDialog(parent, "Save note file", FileDialog.SAVE);
The third argument is either LOAD or SAVE. Set the directory.
d.setDirectory(".");
If you have a default file name that you expect the user to choose,
supply it here.
d.setFile(filename);
2. Then show the dialog box.
d.show();
-
Page 287
-
Replace if (d != 0) ... with if (filename != null) ...
-
Page 287
-
Add this line "This feature does not currently work." after the line
"sets the initial file mask for the file dialog."
-
Page 290
-
In the note, replace method with // method
-
Page 297
-
The Parameters for KeyUp, replace "key the key that is pressed" with
"key the key that is released"
-
Page 304
-
At the bottom of this page, replace public boolean handleEvent(Event
e) with public boolean handleEvent(Event evt)
-
Page 305
-
In the TIP, change private yellowButton; to private
Button yellowButton;
-
Page 306
-
The method setPageIncrement(int l) should return void. Also at the
end of next paragraph, add "This method does not currently work
correctly on all platforms."
-
Page 309
-
In the first paragraph, replace WINDOW_MOVE with WINDOW_MOVED
-
Page 309
-
The code right below the first paragraph, replace Event.MOVE_EVENT
with Event.WINDOW_MOVED
-
Page 319
-
In the first paragraph, at the end of "You need to quit and restart
Netscape to reload the new version of the applet.", add "You can
avoid this problem by setting both the disk and memory cache size to
0, but then performance suffers." (Note by Cay: I think this is an
urban legend--setting the cache size to 0 doesn't seem to work.)
-
Page 324
-
Replace
if (op == "+") arg += n;
else if (op == "-") arg -= n;
else if (op == "*") arg *= n;
else if (op == "/") arg /= n;
else if (op == "%") arg %= n;
else if (op == "=") arg = n;
with
if (op.equals("+")) arg += n;
else if (op.equals("-")) arg -= n;
else if (op.equals("*")) arg *= n;
else if (op.equals("/")) arg /= n;
else if (op.equals("%")) arg %= n;
else if (op.equals("=")) arg = n;
-
Page 328
-
The font used for the heading of the section on the NAME tag should
be a plain, upper-case italic, NOT a bold, mixed-case italic.
-
Page 334
-
Replace the second import java.awt.*;(on top and bottom
part of this page) with import java.applet.*;
-
Page 334
-
Replace <APPLET CODE="FontTestApplet.class WIDTH = 200
HEIGHT = 200> with <APPLET CODE="FontTestApplet.class"
WIDTH = 200 HEIGHT = 200>
-
Page 336
-
Move the instance variables at the front of the class "Chart" to
the end of the class. Also replace
double values[];
String names[];
String title;
with
private double[] values;
private String[] names;
private String title;
-
Page 339
-
Replace class CalculatorApplet extends Applet with class
PopupCalculatorApplet extends Applet
-
Page 344
-
Replace System.out.println(e.getClass().getName()); with
System.out.println(a.getClass().getName());
-
Page 345
-
The second line from the end, replace "and you many not have seen
the relevant tags." with "and you may not have seen the relevant
tags."
-
Page 351
-
Replace "As we said, we do not want to get into the details about
threads." with "As we said, we do not want to get into the details
about threads and the Runnable interface. See chapter 12
for more information."
-
Page 351
-
Replace class CrawlerApplet extends Applet with class
CrawlerApplet extends Applet implements Runnable
-
Page 351
-
Replace method "start" with
public void start()
{ if(runner != null && runner.isAlive())
runner.resume();
else if(runner.isAlive())
runner.resume();
}
-
Page 353
-
In the method destroy(), replace runner.resume(); with
runner.stop();
-
Page 357
-
In the middle of this page, replace "In this example, we just reuse
the retirement calculator." with "In this example, we just reuse
the calculator."
-
Page 366
-
In method action, remove the first "else if" clause.
-
Page 370
-
In the third paragraph, replace "This gives the user completely safe
set, append, and get array access methods." with "This
gives the user completely safe set, append, and get
vector access methods."
-
Page 377
-
Replace e = (Employee)employee.get(s); with e = staff.get(s);
-
Page 383
-
Replace class PartNumber() with class PartNumber
-
page 383
-
Replace return 13 * description.hashValue() + 17 * version;
with return 13 * description.hashCode() + 17 * version;
-
Page 384
-
In the first paragraph, replace "then a test like the one below..."
with "then a lookup like the one below..."
-
Page 386
-
Replace two API descriptions elements() with Enumeration
elements()
-
Page 393
-
In the method HashSetTest(), "for" loop body name.addItem(f[i]);
needs to be indented
-
Page 396
-
Replace s1.reset(); with a.reset();
-
Page 396
-
Replace Employee e = (Employee)s1.currentElement(); with
Employee e = (Employee)a.currentElement();
-
Page 397
-
Remove the semicolon at the last line
-
Page 403
-
Comment in code saying "do something with ob;" should say "do something
with o;"
-
Page 403
-
Replace return current != 0; with return current !=
NULL;
-
Page 404
-
The call data.reset() in "remove()" of Queue is unnecessary
-
Page 404
-
The private protected mechanism is no longer used in Java
-
Page 413
-
In the PascalCanvas constructor, the "if..else if..else.." block
in inner for loop need to be indented
-
Page 423
-
In C++ note, replace "The throws statement is the same as
..." with "The throws specifier is the same as ..."
-
Page 435
-
The last comment in the example code should be "// stack was empty"
-
Page 437*
-
Indent the paragraph starting with "For example, look at our
Format.java file..."
-
Page 438
-
Replace "Here is the code for the MessageCracker class"
with "Here is the code for the MessageCrackerTest class"
-
page 439
-
At the bottom of this page, in the end of "Netscape has a nice 'Java
Console' (available in the Options menu) that displays all the strings
sent to System.out.", add "(see figure 10-4)"
-
Page 441
-
Replace "Here is the code for the DebugWin class." with "Here is
the code for the DebugWinTest class."
-
Page 443*
-
The program listing is wrong. Please substitute the file \CoreJavaBook\ch10\BuggyButtonTest\ButtonTest.java.
Great--a bug in the debugging chapter...
-
Page 443
-
In the method "action", replace else return false; with
else return super.action(evt, arg);
-
Page 445
-
In the "where" command description, replace "|" with "or"
-
Page 448
-
In the last paragraph, replace "Setting breakpoints in an action
statement works pretty well." with "Setting breakpoints in an
action method works pretty well."
-
Page 456
-
In the second paragraph, replace "FileInputStream and
FileOutputStream give you an input stream ..." with "FileInputStream
and FileOutputStream give you input and output streams
..."
-
Page 458
-
At the very bottom of this page, replace "Java has no method to support
that." with "Use writeChars for that purpose."
-
Page 463
-
Below the line java.io.PushbackInputStream, add line
. PushbackInputStream(InputStream in)
-
Page 463
-
Replace "constructs a stream a with one-character lookahead." with
"constructs a stream with a one-character look-ahead.".
-
Page 464
-
Replace BufferedOutputStream(OutputStream in) with BufferedOutputStream(OutputStream
out)
-
Page 464
-
Replace BufferedInputStream(InputStream in, int n) with
BufferedOutputStream(OutputStream out, int n)
-
Page 466
-
In the API note for String nextToken(), replace "Throws
a NoSuchElementException if the are no more tokens." with
"Throws aNoSuchElementException if there are no more tokens."
-
Page 466
-
Replace "These three delimiters are used ..." with "These four delimiters
are used ..."
-
Page 468
-
Replace void readData(Employee[] e, DataInput in) with
Employee[] readData(DataInputStream in)
-
Page 468
-
In the third paragraph, remove "This also discards the prior contents
of e."
-
page 468
-
In the method "readData", replace e[i] = new Employee("", 0,
null); with e[i] = new Employee();
-
Page 469
-
In the first "try" block, add os.close(); at the end, in
the second "try" block, add is.close(); at the end
-
Page 469
-
In the class "Employee", before the method print(), add public
Employee() {}
-
page 471
-
Replace the code static String readFixedString(int size, DataInput
in) at the bottom of the page with the code on page 474-475
-
Page 472
-
In the method "readData", replace DataIO.readFixedString(name,
NAME_SIZE, in); with name = DataIO.readFixedString(NAME_SIZE,
in);
-
Page 478
-
Replace the method "readData" with the one on page 479
-
Page 478
-
Replace "take care of their data fields." with "take care of its
data fields."
-
Page 484
-
The code segment at the top, replace the comment // save parent
class with // read(restore) parent class
-
Page 488
-
At the bottom of the page, replace salary = readDouble(",salary=");
with salary = ps.readDouble(",salary=");
-
Page 493
-
In the method writeString, replace print((char)ch); with
print(ch);
-
Page 493
-
In the method writeString, remove StringBuffer b = new StringBuffer(s.length()
+ x.length() + 2);
-
Page 503
-
The headers for chapter 12, "Multithreading", are all numbered as
chapter 10. They should be 12
-
Page 504
-
On the CD-ROM, the method bounce() (in ch12\Bounce directory) sleeps
for 5 milliseconds, not 10
-
Page 506
-
Remove "Before we can get the ball to bounce correctly, we need to
make one more change inside the ball's run method. The original
bounce code kept checking the system time, and only moved the
ball after 5 milliseconds had elapsed."
-
Page 511
-
Replace "Figure 10-4 shows the states that ..." with "Figure 12-5
shows the states that ..."
-
Page 522
-
Replace class ImageLoader extends Thread with class
ImageLoader extends ThreadGroup
-
Page 527
-
In the method run(), replace if(to >= from) to++; with
if(to == from) to = (to + 1) % Bank.NACCOUNTS;
-
Page 537
-
In class "TimerTest", cross out the line Canvas canvas;
-
Page 540
-
The code segment in the middle, replace "|" with "}"
-
Page 543
-
In the method stop(), replace runner.isActive() with runner.isAlive()
-
Page 559
-
Replace s.start(); with t.start();
-
Page 561
-
In the class "ThreadedEchoHandler", remove Socket incoming;
and int counter; In the end of the class, add
private Socket incoming;
private int counter;
-
Page 561
-
In the class "ThreadedEchoHandler", add public in front
of ThreadedEchoHandler(Socket i, int c)
-
Page 561
-
Add "public" in front of "class ThreadedEchoServer" and move this
class to the beginning of the code
-
Page 565
-
In the method init(), add line setLayout(new BorderLayout());
at the beginning
-
Page 565
-
In the method init(), replace add("South", p); with
add("North", p);
-
Page 565
-
In the method action, remove the first "else if" clause
-
Page 566
-
In the method paint, replace int x = 0; with int x =
80;
-
Page 567
-
In the last paragraph, replace "When the user clicks the Send button,"
with "When the user clicks the Mail button,"
-
Page 568
-
Replace "it wil not use port 8189." with "it will not use port 8189."
-
page 575
-
In method action, remove the first "else if" clause
-
Page 577
-
Cross out the line private int m = 1;
-
Page 580
-
The second line from the end, replace "Then the applet shows a list
of cities in the list box on the left." with "Then the applet shows
a list of cities in the list box on the right."
-
Page 582
-
Replace String query = "/Weather_Text/U.S._City_Forecasts" +
state; with String query = "/Weather_Text/U.S._City_Forecasts"
+ "/" + state;
-
Page 582
-
Replace int i = line.indexOf('0', 1); with int i = line.indexOf("0/",
1);
-
Page 583
-
Replace String query = "/Weather_Text/U.S._City_Forecasts" +
state; with String query = "/Weather_Text/U.S._City_Forecasts"
+ "/" + state;
-
Page 585
-
In the last line, replace "between the corporate network to the Internet,"
with "between the corporate network and the Internet,"
-
Page 586
-
In the first paragraph, it's William R. Cheswick, not William K.
Cheswick
-
Page 588
-
In class ProxySvr, remove int j = 0; and j++;
-
Page 588
-
In class ProxySvr, add "public" in front of the "class ProxySvr"
-
Page 589
-
In main method, replace if(pos < 0) throw e; with if(pos2
< 0) throw e;
-
Page 592
-
In fifth paragraph, replace "Neither C nor Java" with "Neither C
nor Perl"
-
Page 597*
-
The Perl script has two errors. The code $service_name == "http"
should read $service_name eq "http", and likewise
$service_name == "gopher" should be $service_name
eq "gopher". Of course, a really well-designed language would
not lead programmers astray with spurious definitions of ==
for strings... (see page 65)
-
Page 613
-
The Calculator class is on page 264, not 339
-
Page 696
-
In the Employee_raiseSalary function, replace ClassEmployee
with ClassEmployee*.
*: fixed in second printing.
We would like to thank Kamal Abdali, Richard Adler, Mattas Almgre, Ram
Bala, Fred Ballard, Alexander R. Barwick, Greg Bell, Bob Bennett, Jeff
Bensman, Michael Berman, Clemens Bertram, Michael Best, Steve Betz,
Eric L. Blair, Dan Buffum, Mike Carr, Mark Castillo, Mark Chamness,
Chris Chang, James Chen, Steven Chow, William Christ, Keh-Cheng Chu,
Bob Clarke, Dave Claussen, Gary Clayburg, Michael William Clayton,
Steve Cooke, Marcus Crafter, William Crawford, Anand Daga, Neil Daswani,
Rob Day, Chris Dennis, John Deacon, Dilip Deodhar, Robert Doesburg,
Richard Domer. Scott Dunbar, John Dutton, Carlos Escalante, Bruce Eckel,
John Engelman, Thomas Engelin, Hilmi Erdem, Bruce Evans, Walt Farrell,
Alan C Francis, James Francis, Neil Francis, Jay Freedman, Sid Frost,
Michael Fuerst, Dave Fuller, Jack Gage, Art Gittleman, David Glaude,
Paul Glezen, Michael Godfrey, Thomas Goettsche, Roy Goldman, Aryeh
Goldsmith, Adolfo Grego, Chuck Han, William Harris, Alan Hartman, Jeff
Heuer, David Hills, Erik Hjelmes, Chuck Horowitz, Dave Hsu, Edwin Huizinga,
Waikwan Hui, Jason Hulance, David C. Hume, Francis Hwang, Kel Hunt,
Mahesh Inturi, Shinichi Iwamoto, Per Kromann Jacobsen, Miguel C. Jardine,
Sjaak Janssen, Dan Jensen, Thomas Johannesson, Bob Johnsen, Russell
Johnston, Yue Kang, David M. Karr, Mark Kinzie, Thomas Kirsch, Henrik
Kjell, Greg Knight, John Kottal, Eluri Vijaya Kumar, P.J. LaBrocca,
Wilmer Lau, Jim Lawton, Hai N. Le, Tuyen M. Le, April Lee, Joon Suk
Lee, Stephen Lee, Suk Y. Lee, Jocelyn Legault, Eric Lu, Gregory S.
Lyons, Chinh Mai, Chris Maloof, Thomas G. Marshall, Alexandre Martin,
Douglas Martin, Kim McCall, Anthony McCarthy, Donald E. McCollam, Helmut
Messerer, Glen Meints, Ari Meyer, Sandeep Mitra, Alan Murray, Mat Myszewski,
Balasubramanian Narasimhan, David Naylor, Eiji Nishihara, Ralf Nolting,
Jeff O'Brien, John Olsson, John Pagliarulo, Fred Pantalone Jr., Jim
Patrick, Tony Peterman, Gary L Peskin, Doantam Phan, Vanh Phom, L.
Dale Pickering, Craig Prescott, Jim Preston, David Prokop, Joe Rantala,
Larry Reeves, Gene Reznik, Brian Rogoff, Behr de Ruiter, Ursula Rost,
Rob Rucker, Fred Ruddock, Daniel Rybowski, Art Salwin, Steve Sanders,
Matt Sartori, Mike Sauer, Max Schaible, Stefan Schmitz, Craig Schreder,
Warren Seltzer, Scott Shifflett, Pankaj Singhal, Bryan Smith, Jolanta
Snowel, George K. Staropoli, David Starr, Jon Steelman, H. David Stein,
Paul Stoecker, Andrew Swartzbaugh, Leonardo Susatyo, Jonas Svensson,
Kenya Tanaka, Jeff Taylor, Peter Teitelbaum, Janet Traub, Thomas J.
Trop, Brendan Tompkins, Sashank Varma, Nicolas Vekemans, Tis Veugen,
Steve Viens, Ulrich Vollert, Henry Wassermann, Chai Khee Wee, Don Weiss,
Larry Weiss, John N. Welch, Harold Westlund, Richard Williams, Lau
Wilmer, Alice Wong, Rebecca Xue, Hsueh-ching Yen, Seongjun Yun, Rehan
Zaidi, Lenny Zeltser, Song Zhang, Zhihong Zou, Werner Zsolt, John Zukowski,
and a number of anonymous contributors for their bug reports!
Last Modified: 1999-10-25
Back to the Core Java
page.