Below you will find the updates and bug reports for Volumes 1 and 2 of Core Java, Fourth Edition (Java 2).
Notation | Meaning |
---|---|
2p | fixed in second printing |
3p | fixed in third printing |
You can identify which printing of the book you have by opening to the copyright page and locating the row of descending numbers beginning with the numeral 10. The lowest number in that row identifies the printing of the book.
CLASSPATH
environment variable".CLASSES.ZIP
in the lib
directory" with "rt.jar
in the \jdk\jre\lib
directory".chooser.getSelectedFile().getName()
to chooser.getSelectedFile().get Path()
init
method, change JButton cayButton = new JButton("Cay Horstmann");
to cayButton = new JButton("Cay Horstmann");
and change JButton garyButton = new JButton("Gary Cornell");
to garyButton = new JButton("Gary Cornell");
Main
instead of main
), the program will not compile" to "(such as typing Main
instead of main
), the program will not run".object.method(parameters)
" to "Java uses the general syntax object.method(parameters)
"'H'
..." should read "For example, 'H'
..." . "...character, "H"
is a string..." should read "...character, and"H"
is a string..."byte -> short -> int -> long -> float -> double
" to "byte -> short -> int -> long -> float -> double
and char -> int
"CLASSPATH
environment variable as described in chapter 2" to "your CLASSPATH
environment variable as described in appendix III"NumberFormat nf = NumberFormat.getNumberInstance(Locale.GERMAN); System.out.println(nf.format(x)); NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.GERMANY);
to:
NumberFormat nf = NumberFormat.getNumberInstance(Locale.GERMAN); System.out.println(nf.format(x)); nf = NumberFormat.getCurrencyInstance(Locale.GERMANY);
That is, change GERMAN
to GERMANY
(2x) and drop the second NumberFormat
NumberFormat nf = NumberFormat.getNumberInstance(Locale.GERMANY); System.out.println(nf.format(x)); NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.GERMANY);
to:
NumberFormat nf = NumberFormat.getNumberInstance(Locale.GERMANY); System.out.println(nf.format(x)); nf = NumberFormat.getCurrencyInstance(Locale.GERMANY); System.out.println(nf.format(x));
%
, change "Divide by 100" to " Multiply by 100"void DecimalFormat(String pattern)
to DecimalFormat(String pattern)
String s = new Format.form
to String s = new Format
x
Integer in hexadecimal" to "x
, X
Integer in hexadecimal (with lower- or uppercase letters){yourSales >= 1.5 * target)
to (yourSales >= 1.5 * target)
if (x != 0 && 1 / x > 0)
to if (x != 0 && 1 / x + y > x)
. (Editorial note: As Marcia Perry points out, the original condition is equivalent to x > 0
.)Your can retire in
to You can retire in
.+ It'll make you rich!");
to: + "It'll make you rich!");
int numbers[] = new int[high];
int result[] = new int[number];
to:
int[] numbers = new int[high]; int[] result = new int[number];
-r + 1
is the spot at which v
should be inserted" to "-r - 1
is the spot at which v
should be inserted"static void equals
to static boolean equals
. Change "returns true
if object
is an array of the same type" to "returns true
if other
is an array of the same type" Format.print("%4d", odds[i][j]);
should be Format.printf ("%4d", odds[i][j]);
account
objects" to "Account
objects" (1999, Calendar.DECEMBER, 11, 31, 23, 59, 59)
should be (1999, Calendar.DECEMBER, 31, 23, 59, 59)
getTimeinMillis
to getTimeInMillis
("Please enter the month you were born, 1 for January and so on");
to:
("Please enter the month you were born, " + "1 for January and so on");
Employee
class:
public String getName() { return name; }
This method is referenced on page 135
EmployeeTest.java
" to "We had to give this file the name EmployeeTest.java
".raiseSalary
method is a function ..." should be moved up one paragraph to immediately precede the paragraph that begins with "Of the remaining methods in this class ...".byPercent
" to "For example, double byPercent
" (i.e. set double
in Courier)false
or null
).
System.runFinalizersOnExit
to guarantee that finalizer methods are called before Java shuts down. However, this method is inherently unsafe and has been deprecated in Java 2."main
can only access static instance fields of the class" to "Because of this, main
can only access static fields of the class".private static final
)" to "The size of the array and the array itself are declared static
."draw
method, remove the line if (r > high) r = high;
nextRandom
method, remove the line if (pos == BUFFER_SIZE) pos = BUFFER_SIZE - 1;
void play(int rounds)
to public void play(int rounds)
.
) is part of the class
path" to "but if the current directory (.
) is part of the class path". (I.e. class not in Courier)c:\jdk\lib\classes.zip
into c:\jdk\jre\lib\rt.jar
(2x)public void trustMe
to public static void trustMe
.public void CardDeck() { . . . }
to public CardDeck() { . . . }
Manager boss = new Employee("Harry Hacker", 35000, new Day(1989,10,1));
with:
Manager boss = new Manager("Carl Cracker", 75000,
new Day(1987,12,15));
Note: The companion source file is correct.
staff[1] = new Manager("Carl Cracker", 75000, new Day(1987,12,15));with
staff[1] = new Employee("Harry Hacker", 35000,
new Day(1989,10,1));
Note: The companion source file is correct.
x
into an integer, discarding the fractional part" to "converts the value of the expression x
into an integer value, discarding the fractional part".au
format." to "They can be in .au
or .wav
format."private final int MAXMSG = 10;
to private static final int MAXMSG = 10;
toString
method used with the Day
class to give a string representation of the date." to "For example, the toString
method of the Day
class gives a string representation of the date."Object
is the toStrin
g method" to "Another important method in Object
is the toString
method".for (i = 0; i < n; i++) a[i].raiseSalary(3);
to:
for (i = 0; i < n; i++) arr[i].raiseSalary(3);
Change the second occurrence to:
for (i = 0; i < n; i++) arr[i]->raiseSalary(3);
Change
Employee** a; // C++
Object** arr = a;
to:
Employee** staff; // C++ Object** arr = staff;
arr[i].raiseSalary(3)
to staff[i].raiseSalary(3)
. Change arr[i]->raiseSalary(3)
to staff [i]->raiseSalary(3)
. (And set the ->
as a Courier -
followed by a Courier >
.)addElement
method" to "Use the add
method".Object
" to ""The problem arises because vectors store values of type Object
"".void remove
to Object remove
. After "...and shifts down all elements above it.", add " Returns the removed element."v.set(i, new Integer(r.intValue() + 1);
to v.set(i, new Integer(r.intValue() + 1));
(i.e. add a closing parenthesis at the end).Integer
, Long
, Float
, Double
, Byte
, Character
, Void
, and Boolean
. (The first five inherit from the common parent wrapper Number
.)" to "The wrapper classes have obvious names: Integer
, Long
, Float
, Double
, Short
, Byte
, Character
, Void
, and Boolean
. (The first six inherit from the common parent wrapper Number
.)".doubleValu
e()
" and "Doubl
e" to "doubleValue()
" and "Double
". (I.e. drop the unnecessary period and fix up the fonts.)IntegerHolder
to IntHolder
.number
object, ..." to "equivalent of the Number
object, ..." Math
class..." to "you can turn to a couple of handy classes in the java.math
package..."java.lang.reflect
package" to "The three classes . . . in thejava.lang.reflect
package"r += val.toString;
should be: r += val.toString ();
AccessibleObject
a.getClass().getComponentType()
to cl.getComponentType()
System.out
as a parameter to the printf
method.Format.printf(System.out, "%12.4f...)
to Format.printf("%12.4f...)
. That is, remove System.out
from both calls to Format.printf
.&& temp.compare(...
" to "&& temp.compareTo(...
"main
method (i.e. public static void main
, the blank line preceding it and the next five lines following it).hireYear
method, change return 1900 + hiredate.getYear()
to return hiredate.getYear()
instanceof
to check if a object..." to "Next, just as you use instanceof
to check if an object... "e.hireDay = hireDay.clone();
to:
e.hireDay = (Day)hireDay.clone();
TimerListener listener;
to private TimerListener listener;
isSet
refers to the field of the inner object; the name salary
refers to the outer object." to "The name isSet
refers to the isSet
field of the inner object; the name salary
refers to the salary
field of the outer object."$
characters, one cannot simply place a call access$1(harry)
into a Java program and compile it." with "The Java language standard reserves $
characters in variable and method names for system usage."()
in "return new Property ()
".;
after the closing brace under
return new Property() { . . . } // add ; here
JFrame = new FirstFrame();
should read: JFrame frame = new FirstFrame();
WindowListener exitOnClose = New Terminator();
to Terminator exitOnClose = New Terminator();
(for consistency with page 329)void paintComponent(Graphics. g)
" to " void paintComponent(Graphics g)
" (no bold, no period)java.awt.Component
, remove "by calling update
" (2x)Font helvb14 = new Font("Helvetica Bold", Font.PLAIN, 14);
to:
Font helvb14 = new Font("Helvetica", Font.BOLD, 14);
Remove the sentence "When you specify a font by its face name you always use Font.PLAIN
as the second argument of the constructor."
(Editorial comment: The removed sentence described the behavior in 1.2Beta4. 1.2 FCS did not let you request "Helvetica Bold"
--you got plain Helvetica instead. I am hesitant to add a sentence "The suffix Bold
or Italic
is ignored" because I am not confident that behavior is stable. At Java One in May 1999, a presentation from the Java 2D group falsely suggested that it is safe to add Bold
in the font name and Font.PLAIN
in the style. This seems to be a bug that cycles back and forth. Of course, either call ought to obtain the bold font.)
Frame
class" into "Making the fonts and font metrics into variables of our frame class".Color(byte redness, byte greenness, byte blueness)
to:
Color(int redness, int greenness, int blueness)
JFrame
" to "an ancestor of JPanel
". Change
JFrame f = new MyFrame(); f.setBackground(Color.white); f.show();
to:
MyPanel p = new MyPanel();
p.setBackground(Color.white);
contentPane.add(p, "Center");
drawPolyLine
to drawPolyline
int dx = ...
) and the first line of page 304 (int dy = ...
).MediaTracker tracker = new MediaTracker();
to MediaTracker tracker = new MediaTracker(this);
this
pointer. " to "Inside that method, the panel is accessed as the this
reference. "class Terminator implements
" to "class Terminator implements WindowListener
"ActionEvent
(..., selecting a list item, ...)" to "ActionEvent
(..., double-clicking a list item, ...)"focusLost
method, add a space before the &&
, i.e. change : ccField&& !evt.isTemporary()
to ccField && !evt.isTemporary()
.keyEvent.VK_RIGHT
to KeyEvent.VK_RIGHT
int modifiers = evt.getModifiers(); int d; if ((modifiers & InputEvent.SHIFT_MASK) != 0)
with
int d; if (evt.isShiftDown())
mouseClicked
method with
current = find(x, y);
KeyStroke
object that encapsulate a key stroke." to "creates a KeyStroke
object that encapsulate s a key stroke."getModifiers
method, change CONTROL_MASK
to CTRL_MASK
contentPane.add(yellowButton, "South"));
to contenetPane.add(yellowButton, "South");
3
" with "--3
"setSize(300, 300)
to setSize(500, 300)
small = new JRadioButton("Small", false);
medium = new JRadioButton("Medium", true);
to:
smallButton = new JRadioButton("Small", false);Change
mediumButton = new JRadioButton("Medium", true);
group.add(small);
group.add(medium);
to:
group.add(smallButton);
group.add(mediumButton);
static TitledBorder createTitledBorder
, change "... (Border String title,
..." to "...(Border border , String title,
..."createTitledBorder method
: Change "TitleBorder.LEFT
, TitleBorder.CENTER
, TitleBorder.RIGHT
" to " TitledBorder.LEFT
, TitledBorder.CENTER
, TitledBorder.RIGHT
". Change "one of ABOVE_TOP
, TOP
, BELOW_TOP
, ABOVE_BOTTOM
, BOTTOM
, BELOW_BOTTOM
" to "one of the TitledBorder
constants ABOVE_TOP
, TOP
, BELOW_TOP
, ABOVE_BOTTOM
, BOTTOM
, BELOW_BOTTOM
" and clean up the justification.color, shadow
colors for 3D effect" to "highlight , shadow
colors for 3D effect".paintComponent
, add a call to super.paintComponent
like this:
public void paintComponent(Graphics g)
{ super.paintComponent(g);
Font font = (Font)value;
Frame f = new ColorSelect
to:
JFrame f = new ColorSelect
JScrollPane
. Then supply the component to be viewed as the first argument in the constructor." to "To take advantage of this feature, simply make an object of type JScrollPane
. Supply the component to be viewed as the first argument in the constructor."JScrollPane sp = new JScrollPane(viewedComponent,
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER,
to:
JScrollPane sp = new JScrollPane(viewedComponent,(that is, switch the last two lines)
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER,
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS
ScrollPane
to JScrollPane
.JMenu
, which extends JMenuItem
, is missing.new JTextField()
to new JTextField(10)
(2x). Note: Also see the FAQ regarding this program.add(sample, gbc, 0, 3, 4, 1);
to add(sample, gbc, 0, 3, 3, 1);
maxComponentHeight = Math.max(maxComponentWidth,d.height);
to maxComponentHeight = Math.max(maxComponentHeight ,d.height);
menuBar.addMenu(editMenu)
to menuBar.add(editMenu)
.new Object[]
{ "Insert",
"Overtype",
"Read only"
}
to:
new Object[]
{ "Read only",
null,
"Insert",
"Overtype"
}
public void actionPerformed(Event evt)
to public void actionPerformed(ActionEvent evt)
toString
and show the resulting string" should be the matching entry to the right.// import javax.swing.*;
// import javax.swing.border.*;
import com.sun.java.swing.*;
import com.sun.java.swing.border.*;
to:
import javax.swing.*;
import javax.swing.border.*;
gridPanel.add(showPanel);
public AboutDialog(JFrame parent)
to public AboutDialog(JFrame parent) extends JDialog
public AboutDialog(JFrame owner) extends JDialog { . . . }
to:
public class AboutDialog extends JDialog { public AboutDialog(JFrame owner) { . . . } }
showDialog
, change transfer.password = password.getText();
to transfer.password = new String(password.getPassword ());
JTextField password;
to JPasswordField password;
d.getSelectedFile().getName()
to d.getSelectedFile().get Path()
public class GifFilter implements FileFilter
to public class GifFilter extends FileFilter
d.setFileFilter(new FileFilter
to d.setFileFilter(new FileFilter()
...a calculator here>
to:
...a calculator here></APPLET>
<EMBED TYPE="application/x-java-applet;version=1.1" PLUGINSPAGE="http://java.sun.com/products/plugin/1.1 /plugin-install.html" CODE="CalculatorApplet.class" CODEBASE="MyApplets" WIDTH=100 HEIGHT=150> <PARAM NAME="Font" Value="Helvetica"> </EMBED>
to:
<EMBED TYPE="application/x-java-applet;version=1.2" PLUGINSPAGE="http://java.sun.com/products/plugin/1.2 /plugin-install.html" CODE="CalculatorApplet.class" CODEBASE="MyApplets" WIDTH=100 HEIGHT=150 Font="Helvetica"> </EMBED>
Change "Just change APPLET
to EMBED
and add . . ." to "Just change APPLET
to EMBED
, change the PARAM
tag attributes to attributes of the EMBED
tag and add . . ."
done = true;
to:
show error dialog
AccessibleObject.setAccessible(fields, true)
to AccessibleObject.setAccessible( f, true)
.byte b = fin.read();
to byte b = (byte)fin.read();
write
method." to "Similarly, the write
method accepts both a RandomAccessFile
and a DataOutputStream
."
zout.putNextEntry(zout);
send data to ze;
to:
zout.putNextEntry(ze); send data to zout;
class ObjectFileTest
to public class ObjectFileTest
ObjectInputStream(new FileInputStream("test1.dat"));
" to "ObjectInputStream(new FileInputStream("employee.dat"));
"createNewFile()
to:
atomically makes a new file whose name is given by the File
object, if no file with that name exists. That is, the checking for the file name and the creation are not interrupted by other file system activity. Returns true
if the method created the file.
super
from 4 to 5.<b>...</b>
bold for bold" to "<b>...</b>
for bold"super (keyword)
from 69 to 165.resume
to requestResume
paintComponent
to paint
. (Alternatively, it would be a good idea to insert a frame inside the applet's content pane. But that change will have to wait until the 5th edition.)Timer(listener, 1000)
to Timer(1000, listener)
private final int LOCAL = 16;
to private static final int LOCAL = 16;
EventQueue.invokeLater(new Runnable() { public void run() { label.setText(percentage + "% complete"); } }
to:
EventQueue.invokeLater(new Runnable()
{ public void run()
{ label.setText(percentage + "% complete");
}
});
addAll
method, change Iterator iter = iterator();
to Iterator iter = from.iterator();
and add ;
to the end of return modified
.Item
objects"String s = "1411-16-2536"
to:
String s = "987-98-9996"
java.util.TreeMap
, change “tree set” to “tree map” (2x)
boolean put(object key, object value)
to:
Object put(object key, object value)
synchronizedMap
class in the Collections
class..." to "For example, the static synchronizedMap
method in the Collections
class..."public compare(Object a, Object b)
to public int compare(Object a, Object b)
ArraySet streams
to ArrayList streams
(
to BufferedReader in = new BufferedReader (new InputStreamReader(s.getInputStream()));
in middle of page.java.net
class" to "we are importing the java.net
package"getBytes
to getAddress
(2x)Transport.send(message);
", change "multiple recipients, handling attachment, and so on." to "multiple recipients, handling attachments , and so on."URLConnection
" to "then the user can send output to this URLConnection
"URL url=new URL("http:/host/scipt")
so that it's "http://..."
javac -classpath \jswdk\lib\servlet.jar;. proxySvr.java
to javac -classpath \jswdk\lib\servlet.jar;. ProxySvr .java
stmt.commit()
to con.commit()
java ProductClient -Djava.security.policy=client.policy
at top of page to java -Djava.security.policy=client.policy ProductClient
.clear
operation serves no useful purpose" to "the reset
operation serves no useful purpose" ProductImpl.java
implementation is incorrect. See the CD for the correct program. (Or ignore the image file field.)throws RemoteException
after public static void fillWarehouse(WarehouseImpl w)
java EnvClient
)" to "6. Run the client(SysPropClient
)"valueForPathChanged
, change "object
the replacement value returned by the editor" to "newValue
the replacement value returned by the editor"parent
the component over which to pop up the dialog" to "component
the component over which to pop up the dialog"while (next != i && frames[next].isIcon()) next++;
to:
while (next != i && frames[next].isIcon()) next = (next + 1) % frames.length;
path.append(r, false);
to path.append(r, true);
g2.translate(-x, -y); g2.rotate(a); g2.translate(x, y);
to:
g2.translate(x, y); g2.rotate(a); g2.translate(-x, -y);
Change "The first transformation . . ." to "The last transformation (which is applied first) . . ." Change "The third transformation . . ." to "The final transformation . . ."
VALUE_ANTIALIAS_ON
to RenderingHints.VALUE_ANTIALIAS_ON
, VALUE_TEXT_ANTIALIAS_ON
to RenderingHints.VALUE_TEXT_ANTIALIAS_ON
(each 2x)DataFlavor flavor = DataFlavor.stringFlavor; if (selection.isdataFlavorSupported(flavor)) { try { String text = (String)(selection.getTransferData(flavor); do something with text; } catch(Exception e) { ... } }
to:
DataFlavor flavor = DataFlavor.stringFlavor; if (contents.isdataFlavorSupported(flavor)) { try { String text = (String)(contents.getTransferData(flavor)); do something with text; } catch(Exception e) { ... } }
copy
method, change if (text.equals(""))
to if (text == null)
public void setProp(String p) { prop = p; )
to public void setProp(String p) { prop = p; }
java.beans.PropertyChangeEvent
API bar needs to be moved above the PropertyChangeEvent
bullet.Object
the bean source for the property" to "source
the bean source for the property"void removePropertyChangeListener(PropertyChangeListener listener)
to void removePropertyChangeListener(String propertyName, PropertyChangeListener listener)
run
, change while (!interrupted())
to while (!Thread.interrupted())
byte data[]
to byte[] data
DateFormat
class can handle" to "returns all locales that the DateFormat
class can handle"DateFormat
API note, change the first getDateTimeInstance
to getTimeInstance
string.add("=ngstrom")
to string.add("Ångstrom")
" The quick, brown fox"
to "The quick, brown fox"
InputStreamReader =
to InputStreamReader in =
GetObjectArray
to GetObjectArrayElement
and SetObjectArray
to SetObjectArrayElement
Thanks to Knut Åkesson, Lynn Alford, Tony Alicea, Alvaro Antunes, Likun Bai, Steve Bang, Robert Benea, Mark Berkwitt, Joe Bianco, David Blankley, Mike Bopf, Fabiano Bortolotti, George Bradt, David Brown, Jon Byrd, Homer Carlisle, Scott Carpenter, Jose Castellano, Lila Chan, Albert Cheng, Christos Chryssochoidis, Frank Chu, David Cook, George Curry, Brahma Dathan, Geoff Davis, Joe Demasco, Behr de Ruiter, Aniruddha Desai, Ed Deveaux, Judah Diament, Eric Dickinson, Gerwin van Dijken, Howard Dolginoff, John Dougherty, Daniel Dvorak, Judy Enos, Jenn Ferguson, Michael Flanagan, Vitali Fridman, William Gandler, Sam Ganzman, Mark Garratt, Stephen Glow, Bret Goen, John K Gotwals, Michael Grahn, Simon Grönlund, James Guerin, Lev Gurevich, Truls Haaland, Nik Hagan, Margery Harrison, Jeff Hildebrand, David Hills, Susan Hilt, Ron Hofman, Ajit Jaiswal, Loic Julien, Praful Kapadia, Chris Kelly, Craig Kemple, Thomas Klimpel, Greg Knight, Eva Kocsis, Greg Kostal, Jim Kovacs, Per Kromann, Bill Lee, Mali Lev-Ram, Mark Lindberg, Emilio Luna, Mike Luscic, Naz Madhani, Jonathan Mann, Dan Marion, François Martin, Sunil Matta, David Mediavilla, Ross Mehlman, Olga Mironova, Bhadresh Modi, Joe Mundi, Alan Murray, Steve Nicodemus, James Olson, Vince O'Sullivan, Scott Palmer, Ron Parker, Warren Patterson, Marcia Perry, Ajay Pherwani, Vandana Pherwani, Yuriy Podoshev, David Prowak, Boris Pulatov, Suryanarayanan Ramamurthy, Steve Rank, Stuart Reges, Fred Romeo, Anubhav Saini, Art Salwin, Syed Sarwar, Yvon Sauvageau, Volker Schildwach, David Schonberger, Ben Schwarz, Seshadri, Paul Sevinc, Nishith Shah, Rayees Shamsuddin, Peter Shannon, Roman Smolgovsky, Peter Snow, Paul Stanford, Edmund Stephen-Smith, David Sousa, Bruce Strong, Thomas Subias, Isak Swahn, Andrew Swartzbaugh, Kenya Tanaka, Dave Taenzer, Benjamin Townsend, Richard Trahan, Tis Veugen, Ray Wagner, Guangde Wang, Clifford Ward, Jason Warlikowski, Yimin Wei, Jonathan White, Michael William, Jesse Wong, Dan Wolf, Curt Wu, Rebecca Xue, Sugiarto Yamanto, Gary Yee, Michael Zand, Hector Zendejas, Dongdong Zhang, Jian Zhang, Wei Zhang, Christian Zmasek,Werner Zsolt, and a number of anonymous contributors for their bug reports!
Last Modified: 2002-01-06.