You are on page 1of 14

ERRATA Khalid A. Mughal ,Rolf W.

Rasmussen A Programmers Guide to Java SCJP CERTIFICATION

A Comprehensive Primer Third Edition December 2008 ISBN: 0321556054

Errata
Please check here often as we will update the errata regularly.
Errata updates:
Date of
Printi
Pages
update
ng
2009-0102

1st

128, 348, 363, 720, 893, 895

2009-0222

1st

113, 212, 337, 484, 508, 532, 551, 552, 684, 686, 709, 895, 899,
907, 1033

2009-0304

1st

43, 56, 86, 87, 92, 119, 120, 121, 147, 149, 236, 237, 241, 250

2009-0405

1st

66, 725, 929

2009-0524

1st

59, 150, 196, 349, 557, 977, 980, 1000

2009-0715

1st

127, 128, 383, 559, 655, 658, 790, 791, 822, 833, 844, 897, 924,
926, 971, 972

2009-1010

1st

122, 297, 538, 554, 602, 850, 853, 858, 859, 860

2011-0401

1st

65, 232, 277, 403, 540, 674, 770, 797, 813, 873, 910, 933, 968

Acknowledgements:
Many thanks to the following readers for their diligent observations: Ruslan Altynnikov, Mike
Angstadt, William Asher, Dimitar Bonev, Deepak Borania, Christoph Brewing, Frans van Buul,
Pradhumn Choubey, Randy Collins, Benoit Deshaies, Victor Kamat, Gideon Kaplan, Mark Koops,
Stephen Lennon, Kristian Sknberg Lvik, Morteza Manavi-Parast, Joshua Nun, Maniganda
Prakash, Roughcut Readers, Steven Richardson, Nayyara Samuel, Ivan Titov, Kim Ming Yap,
Konstantin Yegupov, Frank Zinner.
Errata list:
The errors listed below are ordered according to their page numbers. Each error is labeled with
all the printings where the error occurred. E.g. "1st printing" indicates that the error occurred in
the first printing, but has been corrected before the second printing, i.e. you won't find this error
in the second printing.
Page 43
1st printing, Figure 3.1:
The two inheritance arrowheads to the right in the figure are on the wrong end of the respective
arrows.
Page 56
1st printing, 5th. line from the top:
CHANGE:
declaration at (1) ...
TO:
declaration at (2) ...
Page 59
1st printing, 5th line of the 1st paragraph:
CHANGE:
same enum contant ...
TO:

same enum constant ...


Page 65
1st printing, RQ 3.10:
CHANGE:
(b) The method call GOOD.getGrade() in (1) can be written without the enum type name.
TO:
(b) The method call GOOD.getGrade() in (1) can be written without the enum constant
name.
Page 66
1st printing, change the declaration in RQ 3.12:
CHANGE:
private char grade;
TO:
protected char grade;
Page 86
1st printing, Example 3.12:
CHANGE:
int[] dataSeq = {6,4,8,2,1}; // Create and initialize an array.
TO:
int[] dataSeq = {8,4,6,2,1}; // Create and initialize an array.
Page 87
1st printing, the first line of the output from Example 3.12:
CHANGE:
64821
TO:
84621
Page 92
1st printing, under "Compiling the program" in Example 3.15:
CHANGE:
flexiPrint(args);
// (10) Warning!
TO:
flexiPrint(args);
// (9) Warning!
Page 113
1st printing, at the beginning of first paragraph:
CHANGE:
Example 4.6 illustrates ...
TO:
Example 4.7 illustrates ...
Page 119
1st printing, middle of the page:
CHANGE:
-cp /pgjc/work:/top/bin/pkg:.
TO:
-cp /pgjc/work:/top/bin:.
Page 120
1st printing, top of the page:
CHANGE:
>javac -cp ../bin/pkg -d ../bin A.java
TO:
>javac -cp ../bin -d ../bin A.java
1st printing, top of the page:
CHANGE:

-cp "../new bin/large pkg"


TO:
-cp "../new bin"
Page 121
1st printing, in the third paragraph:
CHANGE:
the class org.graphics.draw4d.Menu
TO:
the class org.graphics.draw3d.Menu
Page 122
1st printing, last line, the option should be before the class name:
CHANGE:
>java SysProp -DFontSize=18 os.name java.version appName FontSize
TO:
>java -DFontSize=18 SysProp os.name java.version appName FontSize
Page 127
1st printing, RQ 4.7, in options (a) to (d):
CHANGE:
... place the file A.class under ...
TO:
... place the byte code of the class top.sub.A under ...
Page 128
1st printing, RQ 4.9, alternatives (a) to (f):
CHANGE:
The root (/top) of all the paths
TO:
/proj
1st printing, RQ 4.9, 2nd. paragraph:
CHANGE:
... the file A.class for the class top.sub.A?
TO:
... the file A.class of the class top.sub.A?
Page 147
1st printing, Example 4.13:
CHANGE:
// Explicit default constructor
TO:
// Non-default constructor
Page 149
1st printing, middle of the page:
CHANGE:
a final local reference aLight at (5)
TO:
a final local reference tableLight at (5)
Page 150
1st printing, Section "abstract Methods", second to last paragraph, in the last sentence:
CHANGE:
The keyword abstract can only be combined with accessibility modifiers public or private.
TO:
The keyword abstract can only be combined with accessibility modifiers public or protected.
Page 196
1st printing, in order for the explanation in the last paragraph of section 5.12 to make sense,
change the initial value of b2:

CHANGE:
boolean b1 = false, b2 = false, b3 = false;
Boolean b4 = false;
b1 |= true;
// true
b4 ^= b1;
// (1) true, unboxing in (b4 ^ b1), boxing on assignment
b3 &= b1 | b2;
// (2) false. b3 = (b3 & (b1 | b2)).
b3 = b3 & b1 | b2;
// (3) true. b3 = ((b3 & b1) | b2).
TO:
boolean b1 = false, b2 = true, b3 = false;
Boolean b4 = false;
b1 |= true;
// true
b4 ^= b1;
// (1) true, unboxing in (b4 ^ b1), boxing on assignment
b3 &= b1 | b2;
// (2) false. b3 = (b3 & (b1 | b2)).
b3 = b3 & b1 | b2;
// (3) true. b3 = ((b3 & b1) | b2).
Page 212
1st printing, Example 6.4:
CHANGE:
//
case SPICE_LEVEL.HOT: ...
TO:
//
case SPICE_DEGREE.HOT: ...
Page 232
1st printing, RQ 6.17:
CHANGE:
(e)The program will fail to compile if break is by an empty statement.
TO:
(e)The program will fail to compile if break is replaced by an empty statement.
Page 236
1st printing, end of the first bullet:
CHANGE:
(1a)
TO:
(1)
1st printing, Example 6.10:
CHANGE:
printAverage(100, 20);
TO:
printAverage(100, 20);
Page 237
1st printing:
CHANGE:
printAverage(100, 20);
TO:
printAverage(100, 20);

// (1a)
// (1)

// (1a)
// (1)

1st printing:
CHANGE:
printAverage(100, 0);
// (1b)
TO:
printAverage(100, 0);
// (1)
Page 241
1st printing, in first paragraph of "The Exception Class":
CHANGE:
the java.io package (IOException, FileNotFoundException, EOFException, IOError).

TO:
the java.io package (IOException, FileNotFoundException, EOFException).
Page 250
1st printing, Figure 6.13:
CHANGE:
printAverage(100, 0);
TO:
printAverage(100, 0);
1st printing, Figure 6.13:
CHANGE:
printStackTrace();
TO:
printStackTrace();

// (1)
// (2)
// (6)
// (4)

Page 277
1st printing, RQ 6.36:
CHANGE:
Given the following method, which statements will throw an exception, ...
TO:
Given the following method, which statements will throw an exception or an error, ...
Page 297
1st printing, output from Example 7.3:
CHANGE:
Let there be light!
No bill
Large bill: 2000.0
Large bill: 2000.0
Large bill
Small bill
Large bill
Small bill
TO:
Let there be light!
Large bill: 2000.0
No bill
Large bill: 2000.0
Large bill
Small bill
Large bill
Small bill
Page 337
1st printing, at the beginning of the code in RQ 7.31:
INSERT:
import java.util.Map;
import java.util.HashMap;
1st printing, RQ 7.31:
CHANGE:
Select the three correct answers.
TO:
Select the one correct answer.
Page 348
1st printing, RQ 7.37:
CHANGE:

Select the two correct answers:


TO:
Select the three correct answers:
Page 349
1st printing, RQ 7.39(e):
CHANGE:
Each method implementing a single task will result in a class that has high cohesion.
TO:
Each method implementing a single task that is related to the purpose of the class will result in a
class that has high cohesion.
Page 363
1st printing, Example 8.6:
DELETE:
//Filename: Client2.java
Page 383
1st printing, RQ 8.9, option (a):
CHANGE:
... , except final static fields, ...
TO:
... , except final static fields initialized with a constant expression, ...
Page 403
1st printing, RQ 9.6, as first statement in the body of the main() method:
INSERT:
args = null;
Page 484
1st printing, RQ 11.1:
CHANGE:
(e) An array of chars
TO:
(e) An array of bytes
Page 508
1st printing, the numbering of alternatives in RQ 11.19:
CHANGE:
(a) FileOutputStream fos = new FileOutputStream(fileName);
(b) OutputStreamWriter stream = new OutputStreamWriter(fos);
(c) FileOutputStream fos = new FileOutputStream(fileName);
(d) InputStreamWriter stream = new InputStreamWriter(fos);
(e) FileOutputStream stream = new FileOutputStream(fileName);
(f) PrintWriter stream = new PrintWriter(fileName);
(g) FileWriter stream = new FileWriter(fileName);
TO:
(a) FileOutputStream fos = new FileOutputStream(fileName);
OutputStreamWriter stream = new OutputStreamWriter(fos);
(b) FileOutputStream fos = new FileOutputStream(fileName);
InputStreamWriter stream = new InputStreamWriter(fos);
(c) FileOutputStream stream = new FileOutputStream(fileName);
(d) PrintWriter stream = new PrintWriter(fileName);
(e) FileWriter stream = new FileWriter(fileName);
Page 532
1st printing, Section 12.1, first paragraph:
CHANGE:
"in18ln"
TO:
"i18n" (18 refers to the 18 characters deleted in "internationalization")
Page 538

1st printing, in the code snippets:


The field out from the System class is assumed to be statically imported. Therefore the name of
the class is omitted when referencing this field. This is also the case in several places.
Page 540
1st printing, Example 12.3, middle of main() method:
CHANGE:
// Set values in a calendar
calendar.set(Calendar.DAY_OF_MONTH, 33);
calendar.set(Calendar.MONTH, 13);
TO:
// Set values in a calendar
calendar.set(Calendar.DAY_OF_MONTH, 41);
calendar.set(Calendar.MONTH, 12);
Page 551
1st printing, the last line in RQ 12.1:
CHANGE:
anglais, Royaume-Uniint i = 0;
TO:
anglais, Royaume-Uni
Page 552
1st printing, the numbering of alternatives in RQ 12.3:
CHANGE:
(a) calendar.set(Calendar.DAY_OF_MONTH, 1);
(b) calendar.set(Calendar.MONTH, Calendar.JANUARY);
(c) calendar.set(Calendar.YEAR, 2009);
(d) calendar.set(Calendar.DAY_OF_MONTH, 1);
(e) calendar.set(Calendar.MONTH, 12);
(f) calendar.add(Calendar.DAY_OF_MONTH, 1);
(g) calendar.roll(Calendar.DAY_OF_MONTH, 1);
(h) calendar.set(2009, 0, 1);
(i) calendar.set(2009, 1, 1);
TO:
(a) calendar.set(Calendar.DAY_OF_MONTH, 1);
calendar.set(Calendar.MONTH, Calendar.JANUARY);
calendar.set(Calendar.YEAR, 2009);
(b) calendar.set(Calendar.DAY_OF_MONTH, 1);
calendar.set(Calendar.MONTH, 12);
(c) calendar.add(Calendar.DAY_OF_MONTH, 1);
(d) calendar.roll(Calendar.DAY_OF_MONTH, 1);
(e) calendar.set(2009, 0, 1);
(f) calendar.set(2009, 1, 1);
Page 554
1st printing, section 12.6, 2nd. paragraph, last sentence:
CHANGE:
As we shall see, the java.util.Pattern class allows us to compile a regular expression, and the
java.util.Matcher class...
TO:
As we shall see, the java.util.regex.Pattern class allows us to compile a regular expression, and
the java.util.regex.Matcher class...
Page 557
1st printing, Table 12.10, 2nd row:
CHANGE:
\d a digit, i.e., [^0-9]
TO:
\d a digit, i.e., [0-9]
Page 559

1st printing, 2nd to last paragraph (the '.' metacharacter of the regex must be escaped):
CHANGE:
The pattern \d+.\d represents ...
TO:
The pattern \d+\.\d represents ...
Page 602
1st printing, second bullet:
CHANGE:
an Appendable, e.g., a String that implements this interface
TO:
an Appendable, e.g., a StringBuffer that implements this interface
Page 655
1st printing, RQ 13.18, question text:
CHANGE:
... standard input stream ...
TO:
... standard output stream ...
Page 658
1st printing, RQ 13.26, option (f):
CHANGE:
... compileand ...
TO:
... compile and ...
RQ 14.20 (p.734-5, answer on p.924)
Page 674
1st printing, top of the page, replace method name "setData" with "setNext":
CHANGE:
The compiler complains that the method setData(Node<Number>) is not applicable for
the arguments (Node<Integer>), i.e., the method signature setData(Node<Number>)
is not compatible with the method call signature setData(Node<Integer>).
TO:
The compiler complains that the method setNext(Node<Number>) is not applicable for
the arguments (Node<Integer>), i.e., the method signature setNext(Node<Number>)
is not compatible with the method call signature setNext(Node<Integer>).
Page 684
1st printing, Table 14.3:
CHANGE:
Cannot put anything
TO:
Cannot put anything except nulls.
Page 686
1st printing, regarding the RQs in Chapter 14:
The import statements for collections and maps from the java.util package are omitted in the
code of the RQs.
Page 709
1st printing, the last line on the page:
CHANGE:
progCMP = WhoIsComparble.<ProgrammerCMP>max(jProgCMP, jProgCMP); // (5)
TO:
progCMP = WhoIsComparable.<ProgrammerCMP>max(jProgCMP, jProgCMP); // (5)
Page 720
1st printing, Example 14.12:
INSERT:
import java.util.List;
Page 725

1st printing, 3rd line of the last paragraph:


CHANGE:
The compiler issues an unchecked cast warning at (3)
TO:
The compiler issues an unchecked cast warning at (4)
Page 770
1st printing, first line after the example:
CHANGE:
Example 15.9
TO:
Example 15.1
1st printing, output in the middle of the page:
CHANGE:
Sorted list:
TO:
Sorted set:
Page 790
1st printing, 2nd paragraph, 1st. sentence:
CHANGE:
Example 15.13 ...
TO:
Example 15.14 ...
Page 791
1st printing, Example 15.14, (2) (variable name shoudl be strSet):
CHANGE:
// String[] string = strList.toArray(); //(2) Compile-time error!
TO:
// String[] string = strSet.toArray(); //(2) Compile-time error!
Page 797
1st printing, in the middle of the last paragraph:
CHANGE:
(i.e., the last element inserted, is the first element retrieved)
TO:
(i.e., the first element inserted, is the first element retrieved)
Page 813
1st printing, Example 15.19, from the output:
DELETE:
Queue after executing tasks: []
1st printing, Example 15.19, as the last statement in the method testPQ():
INSERT:
System.out.println();
Page 822
1st printing, under subsection "Collection Views", method headers:
CHANGE:
Set<Map, Entry<K, V>> entrySet()
TO:
Set<Map.Entry<K, V>> entrySet()
Page 833
1st printing, RQ 15.30:
CHANGE:
Select two correct answers.
TO:
Select three correct answers.
Page 844

1st printing, 2nd. sentence (more compatible with the discussion on searching in collections on
p. 840):
CHANGE:
(-insertion point)-1
TO:
-(insertion point + 1)
Page 850
1st printing, last two lines:
CHANGE:
>java Concordance Hello World
{d=[9], o=[4, 6], r=[7], W=[5], H=[0], l=[2, 3, 8], e=[1]}
TO:
>java Concordance "Hello World"
{d=[10], o=[4, 7], r=[8], W=[6], H=[0], l=[2, 3, 9], e=[1], =[5]}
Page 853
1st printing, Appendix A, Section A.3:
The SCJP 1.6 Exam (CX-310-065) has been revised, and the following information
supercedes that in Section A.3.
* Number of questions: 60
* Pass score: 58.33 % (35 of 60)
* Time limit: 180 minutes
Page 858
1st printing, Appendix B, Section 1:
The SCJP 1.6 Exam (CX-310-065) has been revised, and objective 1.4
(JavaBeans naming standards, variable-length argument list) has been removed.
This effects the following sections in the book: 3.2, 3.3, 3.8.
Page 859
1st printing, Appendix B, Section 3:
The SCJP 1.6 Exam (CX-310-065) has been revised, and objective 3.3
(mainly Serialization) has been removed.
This effects the following sections in the book: 11.3, 11.6.
Page 860
1st printing, Appendix B, Section 4:
The SCJP 1.6 Exam (CX-310-065) has been revised, and objective 4.4
(wait/notify) has been removed.
This effects the following section in the book: 13.6, p. 640-647.
Page 873
1st printing, answer to RQ 3.10:
CHANGE:
(b) is not correct, because without the enum type name, ...
TO:
(b) is not correct, because without the enum constant name, ...
Page 893
1st printing, RQ 7.18, correct the answer:
CHANGE:
(e)
TO:
(d)
Page 895
1st printing, Missing the answers for RQs 7.28 to 7.34:
INSERT:
7.28 (c)
A double cannot be converted to an Integer, unless it is first converted to an int, as in (5).
7.29

(d)

Wrapper objects are immutable, but the following values are interned when they are wrapped
during boxing,
i.e. only one wrapper object exists in the program for these primitive values when boxing is
applied:
boolean values true and false
All byte values (-128, 127)
short values between -128 and 127
int values between -128 and 127
char in the range \u0000 to \u007f
7.30 (a)
Using the new operator creates a new object. Boxing also creates a new object, if one is not
already interned.
7.31 (d)
(a), (b): Compile-time error as a primitive int cannot be compared with null.
(c): The program compiles, but will throw a NullPointerException if the account is not found,
as null cannot be converted to the return type int.
(e): The primitive type int does not have the method intValue(), the numeric wrapper classes do.
Only (d) will result in the program to compile and run without errors.
7.32 (a)
The signatures yingyang(Integer[]) and yingyang(Integer...) are equivalent, and therefore not
permitted in the same class.
7.33 (c)
A primitive value cannot be widened and then boxed implicitly.
The primitive value is boxed to its corresponding wrapper type, and an attempt is made to find
a corresponding formal parameter with the most specific type to which it can be passed.
The var-arg is passed in the method calls as follows:
printFirst(10);
// new Integer[] {new Integer(10)}
printFirst((byte)20);
// new Number[] {new Byte(20)}
printFirst('3', '0');
// new Object[] {new Character(3), new Character(0)}
printFirst("40");
// new Object[] {"40"}
printFirst((short)50, 55);// new Number[] {new Short(50), new Integer(55)}
printFirst((Number[])new Integer[] {70, 75}); // Passed as array of Number
7.34 (c)
A primitive value cannot be widened and then boxed.
Methods with varargs are considered last during method resolution.
The values in the argument list ((byte)5, (byte)10) are boxed first to obtain (Byte(5), Byte(10))
which are passed to the formal parameter list (Number n1, Number n2).
Note that Byte is a subtype of Number, not of the other wrapper classes.
The values in the argument list (5, 10) are boxed first to obtain (Integer(5), Integer(10))
which are passed to the formal parameter list (Integer i1, Integer i2).
The values in the argument list (5L, 10) are boxed first to obtain (Long(5), Integer(10))
which are passed to the formal parameter list (Number n1, Number n2).
The values in the argument list (5L, 10L) are boxed first to obtain (Long(5), Long(10))
which are passed to the formal parameter list (Long l1, Long l2).
1st printing, RQ 7.37, correct the answer:
CHANGE:
(c) and (d)
TO:
(b), (c), and (d)
1st printing, in the answer to RQ 7.37:
CHANGE:

The use of inheritance in this code does not define a Planet has-a Star relationship.
TO:
The use of inheritance in this code defines a Planet is-a Star relationship.
Page 897
1st printing, answer to RQ 8.9, 1st. sentence:
CHANGE:
... , except final static fields, ...
TO:
... , except final static fields initialized with a constant expression, ...
Page 899
1st printing, Missing the answers for RQs 9.3 to 9.6:
INSERT:
9.3
(d)
Hard to say how many objects are eligible for garbage collection when control reaches (1),
because it may be that some of the eligible objects have already been finalized.
9.4
(a)
All the objects created in the loop are reachable via p, when control reaches (1).
9.5
(a)
The only object created is the array, and it is reachable when control reaches (1).
9.6
(d)
The method nullify() does not affect the array reference in the main() method.
The array referenced by args is no longer reachable when control reaches (1).
Only the array object and its four Integer objects are reachable when control reaches (1).
Page 907
1st printing, Missing the answer for RQ 11.12:
INSERT:
11.12 (c)
The read() method of an InputStream returns -1 when the end of the stream is reached.
The readX() methods of a DataInputStream throw an EOFException when the end of the stream is
reached.
The IOException class is the superclass of a majority of exceptions relating to I/O issues.
Page 910
1st printing, answer to RQ 12.10:
The correct answer is (g), not (e).
Page 924
1st printing, comment to the answer for RQ 14.20:
We compiled the code in Eclipse, using a proprietary compiler different from javac,
resulting in option (c) reporting a compile-time error.
However, option (c) compiles successfully using javac. We believe this to be a bug in javac.
1st printing, answer to RQ 14.21, add also the following explanation for option (f):
Also, the method is not static, so it cannot be called from the main() method.
Page 926
1st printing, answer to RQ 14.30, last sentence:
CHANGE:
Therefore, of the three alternatives (h), (i), and (j), only (i) is correct.
TO:
Therefore, of the three alternatives (g), (h), and (i), only (i) is correct.
Page 929
1st printing, Missing the answer for RQ 15.5:
INSERT:
15.5 (c)
The generic static method cmp() returns a comparator (implemented as an anonymous class)
that reverses the natural ordering of a Comparable type.
The natural ordering of the class Person is ordering after name first and then after age,
using the reverse comparators. p1 is less than p2 because of name, and p1 is greater than p2,

because of age, as their names are equal.


Page 933
1st printing, answer to RQ 15.32:
CHANGE:
...and (b) in the first assignment.
TO:
...and (c) in the first assignment.
Page 968
1st printing, Q18:
CHANGE:
Select the two correct answers.
TO:
Select the one correct answer.
Page 971
1st printing, Q27, option (d) (variable name should be col2, not Col2):
CHANGE:
col1.containsAll(Col2)
TO:
col1.containsAll(col2)
Page 972
1st printing, Q30:
CHANGE:
Select the one correct answer.
TO:
Select the two correct answers.
Page 977
1st printing, Q40:
CHANGE:
Select the three correct answers.
TO:
Select the two correct answers.
Page 980
1st printing, Q49:
CHANGE:
Select the three correct answers.
TO:
Select the four correct answers.
Page 1000
1st printing, answer to Q49:
CHANGE:
(a), (b), and (e)
Expressions (a), (b), and (e) all call the method hashCode() on valid objects.
(c) is an illegal expression, as methods cannot be called on primitive values.
The call in (d) to the equals() method requires an object as argument.
TO:
(a), (b)), (d) and (e)
Expressions (a), (b), and (e) all call the method hashCode() on valid objects.
The call in (d) to the equals() method, the argument 42 is first boxed and then
promoted to Object.
(c) is an illegal expression, as methods cannot be called on primitive values.
Page 1033
1st printing, under the subentry for "return type":
CHANGE:
covariant
TO:
covariant 292

You might also like