Here you'll find an overview of the
errata for the
OCA/OCP Java SE 7 Programmer I & II Study Guide (Exams 1Z0-803 & 1Z0-804) by Kathy Sierra and Bert Bates (also known as
K&B7).
All errata in this overview are confirmed. For convenience and ease of use this overview is ordered on chapter and page. If you have found a mistake in the book which isn't in this list yet or doubt about a possible mistake, just post a reply in
this thread. Once it is confirmed, it will be added to this overview.
Thank you all for your help!
Chapter 1
page 12: Launching Applications with java
Because
java -version is a valid command, the java command should have brackets around
class (because it's clearly optional). Note: on
the official Oracle documentation about the java command you'll find exactly the same format as currently mentioned in the book.
Currently:
java [options] class [args]
Should be:
java [options] [class] [args]
page 12: Launching Applications with java (2)
According to
the official Oracle documentation about the java command the option
-version displays version information and exits; the option
-showversion displays version information and continues. So to have the same behavior as described in this section option
-showversion must be used.
Currently:
java -version MyClass x 1
Should be:
java -showversion MyClass x 1
page 28: Exam Watch
A semicolon is missing at the end of one of the statements.
Currently:
static final int x = 1
Should be:
static final int x = 1;
page 33: code snippet of class Toon
There is no package statement defined in class
Toon. Because class
Cloo has default access, class
Toon should be in same package as class
Cloo in order to compile successfully. So add the same package statement (as class
Cloo) to class
Toon or assume classes
Cloo and
Toon are both defined in the same source code file.
Currently:
class Toon {
public static void main(String[] args) {
Cloo c = new Cloo();
System.out.println(c.doRooThings()); // No problem; method is public
}
}
Should be:
package notcert;
class Toon {
public static void main(String[] args) {
Cloo c = new Cloo();
System.out.println(c.doRooThings()); // No problem; method is public
}
}
page 52: Instance Variables, code snippet of class Employee
In the code snippet one line of code ends with a comma instead of a semi-colon.
Currently:
private String title,
Should be:
private String title;
page 62: bottom of page, 3rd sentence of last paragraph
A minor typo (another word would be more appropriate).
Currently: Each of the enumerated
CoffeeSize types is actually an instance of
CoffeeSize
Should be: Each of the enumerated
CoffeeSize values is actually an instance of
CoffeeSize
page 65: top of page, 1st sentence of 1st paragraph
A minor typo (a wrong chapter reference).
Currently: that looks like an anonymous inner class (which we talk about in Chapter
8)
Should be: that looks like an anonymous inner class (which we talk about in Chapter
12)
page 79: Self Test, Question 9
In the code snippet the opening curly brace of class Frodo is missing.
Currently:
4. public class Frodo extends Hobbit
Should be:
4. public class Frodo extends Hobbit {
Chapter 2
page 112: Table 2-3
A minor typo (a wrong table id)
Currently: TABLE
1-2 Differences Between Overloaded and Overridden Methods
Should be: TABLE
2-3 Differences Between Overloaded and Overridden Methods
page 120: Figure 2-5
The
class keyword is missing in the class declaration of
Ball.
Currently:
abstract Ball implements Bounceable
Should be:
abstract class Ball implements Bounceable
page 131: Table 2-4
The complete constructor in the 3rd cell of the "Compiler-Generated Constructor Code (in Bold)" column must be in bold (to reflect that it is compiler generated), not just the call to
super().
Currently:
public class Foo {
public Foo() {
super();
}
}
Should be:
public class Foo {
public Foo() {
super();
}
}
page 145: top of page, code snippet
A minor typo in the variable name.
Currently:
// FrogCount using f
Should be:
// frogCount using f
page 145: top of page, paragraph just beneath code snippet
The code snippet accesses a static variable
frogCount and not a static method as mentioned in the paragraph on 3 occasions.
Currently:
- and then use the
f reference to
invoke the
static method!
- But even though we are using a specific
Frog instance to access the
static method
- and so the
Frog class
static method is
run
Should be:
- and then use the
f reference to
access the
static variable!
- But even though we are using a specific
Frog instance to access the
static variable
- and so the
Frog class
static variable is
accessed
page 156: Self Test, Question 4
The grid containing the code fragments is missing the closing parenthesis.
Currently:
Should be:
Chapter 3
page 175: Exam Watch
A variable has to be declared (and initialized) before another variable uses it, even when multiple variables are declared on a single line.
Currently:
int j, k=m+3, l, m=1; // illegal: m is not initialized before k uses it
Should be:
int j, k=m+3, l, m=1; // illegal: m is not declared and initialized before k uses it
page 175: Exam Watch (2)
Variable
x is not initialized before variable
y uses it. If
x,
y, and
z are instance (or class) variables, that line will compile successfully (because these variables get a default value). A local variable doesn't get a default value and must be initialized before it's used, otherwise you'll get a compiler error.
Currently:
int x, y=x+1, z; // illegal: x is not initialized before y uses it
Should be:
int x, y=x+1, z; // illegal (only if local variables): x is not initialized before y uses it
page 188: Array Instance Variables, 2nd paragraph, last sentence
When an array is merely declared, the statement "
Array elements are always given default values" can be confusing as there are no array elements. So regardless of where the array itself is instantiated, the array elements are always given a default value. (The complete discussion can be read
here)
Currently: regardless where the array itself is
declared or instantiated.
Should be: regardless where the array itself is instantiated.
page 192: middle of page, output of ReferenceTest
A minor error in the output.
Currently:
a.height = 10
a.height = 30 after change to be
Should be:
a1.height = 10
a1.height = 30 after change to be
page 211: Two Minute Drill, Garbage Collection
A minor mark-up error.
Currently: The
Class object has a
finalize() method.
Should be: The class
Object has a
finalize() method.
page 215: Self Test, Question 7
As the
Wind class creates a few temporary strings as well (in the print statement), answer choices D to G should explicitly refer to
Wind objects.
Currently:
D. Zero objects are eligible for garbage collection.
E. One object is eligible for garbage collection.
F. Two objects are eligible for garbage collection.
G. Three objects are eligible for garbage collection.
Should be:
D. Zero
Wind objects are eligible for garbage collection.
E. One
Wind object is eligible for garbage collection.
F. Two
Wind objects are eligible for garbage collection.
G. Three
Wind objects are eligible for garbage collection.
page 220: Self Test Answers, Question 3
The possible answer choices are A, B, C, D, E and F. The explanation is describing answer F but referring to it as G.
Currently:
- A, B, D, E, and
G are incorrect.
- and
G is a valid hexadecimal literal that uses an underscore.
Should be:
- A, B, D, E, and
F are incorrect.
- and
F is a valid hexadecimal literal that uses an underscore.
Chapter 4
page 235: Table 4-1, 5th row
If you try to check if
Foo[] is of type
Foo (or
Bar or
Face) using the
instanceof operator, you will get a compiler error.
Currently:
Should be:
Foo[] | Foo, Bar, Face | compiler error |
page 237: middle of page
This statement implies the sum (of
b and
c) is first turned into a
String before being concatenated to another
String. But when a primitive is concatenated to a
String, the primitive is
not converted to a
String first.
Currently: "Add the values of
b and
c together, and then
take the sum and convert it to a String and concatenate it with the
String from variable
a."
Should be: "Add the values of
b and
c together, and then
take the sum and concatenate it with the
String from variable
a."
page 253: Self Test, Question 8
On line 10 of the code snippet, the assignment operator (
=) should be used instead of the equality operator (
==).
Currently:
10. if(b1 || (b2 == true)) s += "y";
Should be:
10. if(b1 || (b2 = true)) s += "y";
page 255: Self Test Answers, Question 7
A minor issue: the exam objective is missing behind the explanation.
Currently: operator's boolean test.
Should be: operator's boolean test.
(OCP Objective 2.5)
Chapter 5
page 268: top of page, 1st paragraph, 1st sentence
Both begin and end index of the
substring method (in the
String class) are zero-based (0 is a legal end index), but the end index is exclusive, whereas the begin index is inclusive. It would probably even be better to rephrase the whole paragraph for improved quality.
Currently: Unfortunately, the ending argument is
not zero-based,
Should be: Unfortunately, the ending argument is
exclusive,
page 283: Figure 5-7
The statement (in the box just beneath the figure) is missing a semicolon at the end.
Currently:
{new Cat("Bilbo"), new Cat("Legolas"), new Cat("Bert")}}
Should be:
{new Cat("Bilbo"), new Cat("Legolas"), new Cat("Bert")}};
page 297: Two Minute Drill, Using ArrayList, last bullet point
The parameters of both the
contains and
indexOf methods are missing (consistency).
Currently:
clear(),
contains(),
get(index),
indexOf(),
Should be:
clear(),
contains(object),
get(index),
indexOf(object),
Chapter 6
page 316: Exam Watch
Using curly braces with a
case is not a compiler error, omitting the colon definitely is.
Currently: In the first example, the
case uses a curly brace and omits the colon.
Should be: In the first example, the
case omits the colon.
page 329: ILLEGAL 'for' declarations, 2nd statement
The variable
x2 is already defined (being the reason why the 1st statement is illegal). So to properly illustrate the intended reason why the 2nd statement is illegal (you can't stuff an array into an int), the variable name of the 2nd statement should be changed.
Currently:
for(int x2 : twoDee) ;
Should be:
for(int i1 : twoDee) ;
page 337: 3rd sentence in last paragraph
When an exception is thrown while the code in the
try block is executing, execution immediately transfers to the appropriate
catch clause (and not to the first line inside that
catch clause).
Currently: execution transfers to
the first line of that exception handler
, line 8 in the catch clause.
Should be: execution transfers to that exception handler
(line 7 in the code).
page 350: 4th sentence in last paragraph
This sentence makes it sound like
RuntimeException is a subclass of Error (which is of course not true). So
RuntimeException should be replaced with any subclass of
Error (e.g.
StackOverflowError,
NoClassDefFoundError,
OutOfMemoryError,...)
Currently: When an
Error or a subclass of
Error (like
RuntimeException) is thrown, it's unchecked.
Should be: When an
Error or a subclass of
Error (like
StackOverflowError) is thrown, it's unchecked.
page 351: bottom of page, AssertionError
In the 1st sentence of the last paragraph (just beneath the Exam Watch)
AssertionError is mentioned for the very 1st time in this study guide. This is still a left-over of dividing the study guide in Part I (for OCA) and Part II (for OCP). Assertions are covered in the OCP part (chapter 7), so for the OCA exam you only need to know that
AssertionError IS-A
Error (so not a subclass of
Exception nor
RuntimeException).
AssertionError is also mentioned on page 357 (1st sentence in 1st paragraph, just beneath the code snippet) and on page 358 (in table 6-2).
page 361: Two Minute Drill, Writing Code Using if and switch Statements, 5th bullet point
A
case constant must be a compile-time constant (just a
final variable is insufficient).
Currently: The
case constant must be a literal or
final variable,
Should be: The
case constant must be a literal or
compile-time constant,
page 361: Two Minute Drill, Writing Code Using if and switch Statements, last bullet point
A
default block (if present) is executed when no
case matches.
Currently: so if
no preceding case matches, the
default block will be entered,
Should be: so if
no case matches, the
default block will be entered,
page 370-371: Self Test, Question 13
If you think
StackOverflowError is a runtime (or checked) exception, you could still get the correct answer for this question. And if you only check the correct answers (and don't read the explanation), you'll never know.
Therefore it might be useful to improve this question as follows:
- change
"ouch" to
"error" (in fragment II) and to
"exception" (in fragment III)
- add these two new answer options G and H:
G.
error is in the output.
H.
exception is in the output.
- after these changes the correct answers would be B, E, and G.
Chapter 7
page 393: Rethrowing Exceptions (only in Kindle Edition)
The code sample just above "Notice the multi-catch is gone..." shows completely unrelated code without any exception handling.
Should be:
1. public void rethrow() throws SQLException, IOException {
2. try {
3. couldThrowAnException();
4. } catch (Exception e) { // watch out: this isn't really
5. // catching all exception sublclasses
6. log(e);
7. throw e; // note: won't compile in Java 6
8. }
9. }
page 394: Exam Watch
A minor mark-up error. This is not an "exam watch", but should be an "on the job!".
page 395: Table 7-3
When a checked exception is added to the
rain() method signature and the exception is caught and rethrown (as in the code examples), this checked exception must also be added to the
ahhh() method signature.
Currently:
Java 6 style | Add another catch block to handle the new exception. | Remove a catch block to avoid compiler error about unreachable code. |
Java 7 with duplication | Add another exception to the multi-catch block to handle the new exception. | Remove an expression from the multi-catch block to avoid compiler error about unreachable code. |
Java 7 without duplication | Add another exception to the method signature to handle the new exception that can be thrown. | No code changes needed. |
Should be:
Java 6 style | Add another catch block to handle the new exception. If the new exception is rethrown in the catch block, add another exception to the method signature to handle the new exception that can be thrown. | Remove a catch block to avoid compiler error about unreachable code. |
Java 7 with duplication | Add another exception to the multi-catch block to handle the new exception and/or add another exception to the method signature to handle the new exception that can be thrown. | Remove an expression from the multi-catch block to avoid compiler error about unreachable code. |
Java 7 without duplication | Add another exception to the method signature to handle the new exception that can be thrown. | No code changes needed. |
page 399: bottom of page, last paragraph
The interface names
Closeable and
AutoCloseable were interchanged with each other. Only the
close method in the
Closeable interface is required to be idempotent. See
the javadoc of AutoCloseable for more information.
Currently:
- For classes that implement
AutoCloseable, the implementation is required to be idempotent.
- For classes that implement
Closeable, there is no such guarantee.
Should be:
- For classes that implement
Closeable, the implementation is required to be idempotent.
- For classes that implement
AutoCloseable, there is no such guarantee.
page 400: Table 7-5, last row
Same issue as on
page 399.
Currently:
| AutoCloseable | Closeable |
Must be idempotent (can call more than once without side effects) | Yes | No, but encouraged |
Should be:
| AutoCloseable | Closeable |
Must be idempotent (can call more than once without side effects) | No, but encouraged | Yes |
page 405: Two Minute Drill, Autoclosable Resources with a try-with-resources statement, 3rd bullet point
Same issue as on
page 399.
Currently:
AutoCloseable 's
close() method throws
Exception and
must be idempotent.
Closeable 's
close() throws
IOException and
is not required to be idempotent.
Should be:
AutoCloseable 's
close() method throws
Exception and
is not required to be idempotent.
Closeable 's
close() throws
IOException and
must be idempotent.
page 410-411: Self Test, Question 8
The answers D and E are the same. Probably E should have the same order for letters
glf as answers A and C. This change doesn't have any effect on the correct answer.
Currently:
E. t2lgf
Should be:
E. t2glf
page 412-413: Self Test, Question 11
Some possible answers include "RuntimeException c" although the example code only contains "RuntimeException a". These answers will never be correct, but might be added to deceive/confuse the reader. Although it's more likely these are just some copy/paste leftovers from question 10 (and thus could/should be removed).
Chapter 8
page 421: Table 8-1, 3rd use case
The 1st step of this use case has some incorrect syntax to create a
Locale instance (probably a copy-edit error).
Currently:
Locale loc = Locale(language, country);new
Should be:
Locale loc = new Locale(language, country);
page 429: The NumberFormat class, code snippet
A (minor) slip-up in a code comment.
Currently:
Locale locFR = new Locale("fr"); // France
Should be:
Locale locFR = new Locale("fr"); // French
page 443: Locating Data via Pattern Matching, 2nd sentence
A minor typo in the class name.
Currently: we've been using:
java.util.regex.Pattarn and
Should be: we've been using:
java.util.regex.Pattern and
page 458: top of page, code snippet (just beneath 1st paragraph)
The code snippet uses a non-existing reference variable (
args[0]).
Currently:
Locale locale = new Locale(args[0], "CA");
Should be:
Locale locale = new Locale("en", "CA");
page 466: Self Test, Question 2
The
Locale instance should have been created using the constructor with 2 parameters:
language and
country (instead of using the 1 parameter version using
language_country).
Currently:
ResourceBundle rb = ResourceBundle.getBundle("Flag", new Locale("en_CA"));
Should be:
ResourceBundle rb = ResourceBundle.getBundle("Flag", new Locale("en", "CA"));
page 467: Self Test, Question 3
On a Unix/Linux machine the string "
^23 *$76 bc" is actually translated into the string "
^23 *6 bc" before it is passed to the program ("
$7" is taken to be a variable without a value assigned to it). On a Windows machine the string is used as-is, resulting in different outputs (and none of the answers will be correct). The string "
^23 *6 bc" should be used in answers A until D (inclusive).
Currently:
A. java Quetico "\b" "^23 *$76 bc"
B. java Quetico "\B" "^23 *$76 bc"
C. java Quetico "\S" "^23 *$76 bc"
D. java Quetico "\W" "^23 *$76 bc"
Should be:
A. java Quetico "\b" "^23 *6 bc"
B. java Quetico "\B" "^23 *6 bc"
C. java Quetico "\S" "^23 *6 bc"
D. java Quetico "\W" "^23 *6 bc"
page 470: Self Test, Question 7
The provided code will actually put two spaces between the 0 and the 9. So, none of the answers are correct. One of the spaces in 1st print-statement should be removed (or replaced with an empty string).
Currently:
System.out.print(sb.length() + " " + sb + " ");
Should be:
System.out.print(sb.length() + "" + sb + " ");
page 472: Self Test, Question 11
To have exactly the same output as in the possible answer, the 1st occurence of the
println statement should be a
print statement instead.
Currently:
System.out.println(nf.format(d) + " ");
Should be:
System.out.print(nf.format(d) + " ");
page 475: Self Test Answers, Question 7
According to
the javadoc of StringBuilder the
insert method will throw an exception if the
offset is greater than the
length (and not the
capacity) of the sequence.
Currently: Note: Invoking
insert() past the current
capacity will cause an exception to be thrown.
Should be: Note: Invoking
insert() past the current
length will cause an exception to be thrown.
Chapter 9
page 483: Using FileWriter and FileReader, class Writer2
The
read method of
FileReader returns the number of characters (not bytes) read.
Currently:
System.out.print(size + " "); // how many bytes read
Should be:
System.out.print(size + " "); // how many characters read
page 494: Figure (just above Exam Watch)
The
Files class uses
Path objects, not the
Paths class.
Currently: An arrow from
Files to
Paths (with label
uses)
Should be: An arrow from
Files to
Path (with label
uses)
page 497: Creating Files and Directories, 1st sentence in 1st paragraph
A minor mark-up error.
Currently: With I/O, we saw that a
File doesn't exist just because you have a
File object.
Should be: With I/O, we saw that a file doesn't exist just because you have a
File object.
page 498: Creating, Moving and Deleting Files, 1st and 2nd code blocks
The file name used for
source should be clearer.
Currently:
Path source = Paths.get("/temp/test1");
Should be:
Path source = Paths.get("/temp/test1.txt");
page 504: top of page, first paragraph, last two sentences
A
Path doesn't know whether it's a file or a directory; on Unix/Linux and Windows
Model.pdf could be a directory and
dir could be a file. So the output of the
resolve() call isn't nonsense, but the expected output based on the input.
Currently: The sixth one tries to resolve a directory within the context of a file. Since that doesn't make any sense, Java just tries its best and gives you nonsense
Should be: The output of the sixth one looks a little bit weird, but Java does the only right thing to do here. For all it knows the
Path referred to by
Model.pdf may be a directory and the
Path referred to by
dir may be a file!
page 508: Table 9-6, header
A minor slip-up in the 3rd (last) column.
Currently:
Description | I/O Approach | Approach |
Should be:
Description | I/O Approach | NIO.2 Approach |
page 510: 2th sentence in 1st paragraph
A minor typo: the FileTime class (in package java.nio.file.attribute) is with upper case F and T.
Currently: and only pass
Filetimes
Should be: and only pass
FileTimes
page 511: Working with DosFileAttributes, last paragraph
When you use the
setAttribute method in the
Files class with an unknown attribute name (like "
dos:readOnly") an
IllegalArgumentException will be thrown (as mentioned in the
javadoc of Files.setAttribute). Important to know: the attribute names are case-sensitive!
Currently: If you forget and use the
String "
readOnly," Java will
silently ignore the statement and the file will still allow anyone to write to it.
Should be: If you forget and use the String "
readOnly," Java will
throw an IllegalArgumentException.
page 515: code snippet of class RemoveClassFiles
According to the
javadoc of Path.endsWith(String) the method works exactly the same as
Path.endsWith(Path). Therefore you'll need to invoke
Path.toString() first in order to get the described behaviour.
Currently:
if (file.getFileName().endsWith(".class"))
Should be:
if (file.getFileName().toString().endsWith(".class"))
page 518: top of page, 2nd sentence in 1st paragraph
In the preceding code (page 517, middle of page) the enum constant
FileVisitResult.SKIP_SUBTREE is used (and not
FileVisitResult.SKIP_SIBLINGS).
Currently: Now what do you think would happen if we changed
FileVisitResult.SKIP_SIBLINGS to
FileVisitResult.TERMINATE?
Should be: Now what do you think would happen if we changed
FileVisitResult.SKIP_SUBTREE to
FileVisitResult.TERMINATE?
page 521: middle of page, code snippet (with 4 Paths and 1 glob)
A note should be added to this code snippet: the
Paths with an asterisk (
path1,
path2, and
path4) will throw an
InvalidPathException when executed on a Windows machine, because the asterisk is not a valid character for files and/or directories. The four
Path objects will be successfully created on a Unix/Linux machine.
page 524: bottom of page, 1st sentence of note (last paragraph)
A minor typo in the class name.
Currently: can be found in the
StandardWatchEventsKinds class
Should be: can be found in the
StandardWatchEventKinds class
page 532: Self Test, Question 4
When
fred is entered as username, line 8 will print
hello fred. But that line is not included in any of the answers. So line 8 must be removed to match the possible answers with the code (and all lines of code starting with 9 should be renumbered).
Currently:
7. String u = c.readLine("%s", "username: ");
8. System.out.println("hello " + u);
9. String pw;
Should be:
7. String u = c.readLine("%s", "username: ");
8. String pw;
page 539: Self Test Answers, Question 8
There is a difference between copying and moving a nonempty directory which isn't reflected in the current explanation.
Currently: E is correct because a directory containing files or subdirectories
is copied or moved in its entirety.
Should be: "E is correct because a directory containing files or subdirectories
is moved in its entirety. When a nonempty directory is copied, an empty directory is created in the target location (entries in the directory are not copied).
Chapter 10
page 552: middle of page, paragraph "If getInstance() weren't public"
If
getInstance() weren't
public, the method would have no access modifier and be package-private. A package-private
static method can be invoked by every instance and class method in the same package.
Currently: because only
static[i] methods of the class Show[/i] would be able to use the singleton.
Should be: because only
methods in the same package would be able to use the singleton.
page 561: middle of page, 1st sentence after diagram
A minor issue. This sentence is worded incorrectly as
BookDao is actually an interface (and not an abstract class).
Currently: To review,
Student only interacts with the
two abstract classes Factory and BookDao.
Should be: To review,
Student only interacts with the
abstract class Factory and the interface BookDao.
page 567: Self Test, Question 3
One of the requirements of the singleton design pattern is a private constructor. So in order for answer F to be correct a private constructor must be added to the
F class.
Currently:
private static final F f = new F();
Should be:
private static final F f = new F();
private F() {}
page 571: Self Test Answers, Question 5
A wrong choice of words: a class extends (not implements) another class.
Currently: Not shown is a class
implementing class
G that actually creates the object.
Should be: Not shown is a class
extending class
G that actually creates the object.
Chapter 11
page 581: Overriding hashCode(), 5th line from the bottom
The word
legal means that it is valid Java code (which will not cause a compiler error). So an appropriate or correct implementation should of course be legal.
Currently: This does
not mean legal and does not even mean efficient.
Should be: This does
mean legal, but does not mean efficient.
page 590: Figure 11-2 (only in electronic version of the book)
A minor typo (a wrong figure id)
Currently: FIGURE
7-2 The interface and class hierarchy for collections
Should be: FIGURE
11-2 The interface and class hierarchy for collections
page 611: bottom of page, last bullet point
A minor typo (a wrong argument index)
Currently: using the same
Comparator, which is passed as the
second argument to the
binarySearch() method.
Should be: using the same
Comparator, which is passed as the
third argument to the
binarySearch() method.
page 618: middle of page, output of class MapTest
The
hashCode() method of class
Dog is overridden and returns
name.length(). So when a
Dog instance with name "aiko" is printed, the
toString() method returns
Dog@4 (and not
Dog@1c).
Currently:
Dog@1c
DOG
CAT key
Should be:
Dog@4
DOG
CAT key
page 678: Self Test Answers, Question 1
In the explanation the answers A and B are interchanged.
Currently:
-
A is correct.
-
B is incorrect because
List is an interface,...
Should be:
-
B is correct.
-
A is incorrect because
List is an interface,...
Chapter 12
page 688: top of page, 1st bullet point
In static method code within the outer class the inner class name name does not have to include the outer class's name.
The code snippet in this post uses only the inner class name and compiles successfully.
Currently: From outside the outer class instance code
(including static method code within the outer class), the inner class name must now include the outer class's name
Should be: From outside the outer class instance code, the inner class name must now include the outer class's name
page 711: Self Test Answers, Question 6
A minor issue. This sentence is worded incorrectly as an object is referenced by a variable.
Currently: The
variable referenced by
f is an instance
Should be: The
object referenced by
the variable f is an instance
Chapter 13
page 728: top of page, java.lang.Thread header
A word is missing in the header of the
java.lang.Thread Class (just beneath Exam Watch).
Currently: from the
java.lang.Thread Class
Should be:
Methods from the
java.lang.Thread Class
page 766: Two Minute Drill, Transitioning Between Thread States, 8th bullet point
A thread can never go directly from the waiting state to the running state. The 2nd sentence (and certainly the part in between parentheses) is hard to understand in the correct context, certainly for non-native English speakers. So it should definitely be adjusted and rephrased.
Currently: It will go directly from waiting to
running (well, for all practical purposes anyway).
Should be: It will go directly from waiting to
runnable (well, for all practical purposes anyway).
Chapter 14
page 785: Certification Objectives, 2nd bullet point
A minor typo in the package name.
Currently: in the
java.util.cuncurrent.locks Package
Should be: in the
java.util.concurrent.locks Package
page 804-805: code snippet about LinkedTransferQueue
A
LinkedTransferQueue is unbounded, so methods will never block, return
false or throw an
IllegalStateException.
Currently:
boolean b1 = tq.add(1); // returns true if added or throws
// IllegalStateException if full
tq.put(2); // blocks if bounded and full
boolean b3 = tq.offer(3); // returns true if added or false
// if bounded and full
// recommended over add
boolean b4 =
tq.offer(4, 10, MILLISECONDS); // returns true if added
// within the given time
// false if bound and full
Should be:
boolean b1 = tq.add(1); // always returns true
tq.put(2); // will never block
boolean b3 = tq.offer(3); // always returns true
// recommended over add
boolean b4 =
tq.offer(4, 10, MILLISECONDS); // always returns true and
// will never block
page 810: middle of page (code snippet just beneath NewThreadExecutor)
A minor typo in the method name.
Currently:
ex.executor(r);
Should be:
ex.execute(r);
page 818: top of page, 1st sentence
The
compute() method is not defined in the
ForkJoinTask class.
Currently: but the following methods are important:
compute(),
fork(), and
join().
Should be: but the following methods are important:
fork() and
join(). From the
ForkJoinTask subclasses
RecursiveTask and
RecursiveAction you only have to know the
compute() method.
page 832: Self Test, Question 2
When you invoke the
remove method of the
List interface with an
int parameter, the
remove(int index) is executed (and
not remove(Object o)). Therefore number 6 would be removed (and not number 2 as stated in the explanation). If
remove(Object o) is executed (instead of
remove(int index)), the explanation is spot-on. (note: it doesn't affect the correct answer)
Currently:
cowList.remove(2);
Should be:
cowList.remove(Integer.valueOf(2));
page 834: Self Test, Question 8
The
getHighScores method returns a read-only view of
highScores that is intended to be guarded by the lock. But the provided code is not thread safe: the caller may read from the list while another thread is running the
addScore method; for example in the middle of sorting it. Although it doesn't matter for answering the question correctly, it's better to improve the code and make it thread safe by returning an unmodifiable snapshot of
highScores.
Currently:
return Collections.unmodifiableList(highScores);
Should be:
return Collections.unmodifiableList(new ArrayList<>(highScores));
Chapter 15
page 842: Starting Out: Introduction to Databases and JDBC
Although the main JDBC interfaces define a contract, it seems that not all versions of every vendor's JDBC implementation seems to be fully compliant with the contract (examples:
here,
here and
here). So a note should be added somewhere in this (introductory) section to make readers aware of these inconsistencies (so they are not surprised/confused when executing code snippets).
page 850: middle of page
An obvious copy-edit mistake. The figure shown is exactly the same figure as on page 494 in chapter 9. It should be the
Books_by_Author table with sample data (and 2 notes). So the following table (and 2 notes) should replace the figure about I/O and NIO.
Bob's Books Books_by_Author Join Table Sample Data
AuthorID | ISBN |
1000 | 142311339X |
1001 | 0689852223 |
1002 | 0525423656 |
1000 | 1423153627 |
1003 | 031673737X |
1004 | 0545078059 |
1004 | 0803733428 |
1008 | 9780545236 |
1009 | 9780545236 |
- Notice that AuthorID has duplicate entries - it's not the primary key. Instead, it represents that the author with this id has written these two books.
- Notice that the last two rows have the same ISBN but different AuthorID values - this represents a book with two authors.
page 871: top of page, last sentence in 1st paragraph
A minor typo (a wrong table reference).
Currently: the
ResultSet methods shown in Table 15-
7.
Should be: the
ResultSet methods shown in Table 15-
8.
page 872: top of page, code snippet
A minor typo (a wrong column name in query statement). Not a mistake, but for consistency:
from should be uppercase.
Currently:
String query = "SELECT Title, PubDate, UnitPrice from Book";
Should be:
String query = "SELECT Title, PubDate, Price FROM Book";
page 874: code snippet in the getTime-method parapraph
A copy/paste mistake (a wrong method name).
Currently:
java.sql.Time time = rs.getString("FinishTime");
Should be:
java.sql.Time time = rs.getTime("FinishTime");
page 881: middle of page, TYPE_SCROLL_SENSITIVE parapraph
A minor typo (another verb would be more appropriate).
Currently: A cursor can be
changed in the results
Should be: A cursor can be
moved in the results
page 886: Figure 15-6
The invocations are wrongly numbered. The correct order should be 1, 3, and 2.
Currently:
1. rs.absolute(2);
2. rs.relative(-3);
3. rs.relative(5);
Should be:
1. rs.absolute(2);
3. rs.relative(-3);
2. rs.relative(5);
page 892: paragraph "public void deleteRow() throws SQLException"
A logic mismatch about the capability of a
ResultSet to detect deletions.
Currently: When a
ResultSet can detect deletions, the deleted row is removed from the
ResultSet. When the
ResultSet cannot detect deletions
Should be: When a
ResultSet cannot detect deletions, the deleted row is removed from the
ResultSet. When the
ResultSet can detect deletions
page 893: Figure 15-7
The correct method name to delete a row in a
ResultSet is
deleteRow() (not
delete()).
Currently:
- in the caption of the figure: A
ResultSet after
delete() is called
- in the code snippet:
rs.next()
rs.delete()
Should be:
- in the caption of the figure: A
ResultSet after
deleteRow() is called
- in the code snippet:
rs.next()
rs.deleteRow()
page 901: paragraph "public String getMessage()"
The
getMessage() and the
toString() methods of class
Exception are not overridden in
SQLException, so both will print the same error message. How detailed this message is, is vendor dependent.
Currently:
But this method returns the detailed reason why the exception was thrown. Note that this is not the same message that is returned from the
toString() method, i.e., the method called when you put the exception object instance into a
System.out.println method. Often, the message content
SQLState and error code provide specific information about what went wrong.
Should be:
This method returns the detailed reason why the exception was thrown. Often, the message content
SQLState and error code provide specific information about what went wrong.
page 905: bottom of page, last paragraph
An interface extends (or inherits from) another interface, it doesn't implement an interface.
Currently: so that
Connection,
Statement, and
ResultSet all
implement the
AutoCloseable interface
Should be: so that
Connection,
Statement, and
ResultSet all
extend the
AutoCloseable interface
page 914: bottom of page, last code snippet
A minor typo (another class name would be more appropriate).
Currently:
RowSetProvider.newFactory("com.example.MyRowSetProvider", null);
Should be:
RowSetProvider.newFactory("com.example.MyRowSetFactory", null);
page 919: Disconnected RowSets: CachedRowSet
A wrong (non-existing) class name is used.
Currently: To initially load a
CachedResultSet
Should be: To initially load a
CachedRowSet
page 923: top of page, just beneath code snippet
A transaction includes all SQL statements, not only queries.
Currently: A transaction includes all of the SQL
queries you execute
Should be: A transaction includes all of the SQL
statements you execute
page 927: top of page, code snippet
Savepoint
sp1 is not in scope when it is used to rollback a transaction (in the
catch block of the second
try block). It should be declared before the first
try block (instead of inside this block).
Currently:
try {
result1 = stmt.executeUpdate(query1);
result2 = stmt.executeUpdate(query2);
Savepoint sp1 = null;
Should be:
Savepoint sp1 = null;
try {
result1 = stmt.executeUpdate(query1);
result2 = stmt.executeUpdate(query2);
page 929: penultimate sentence in penultimate paragraph
A wrong method name is used: a
Statement is created using the
createStatement (not
createConnection) method.
Currently: the
Connection object (the
Connection.createConnection(int, int) method creates a
Statement object)
Should be: the
Connection object (the
Connection.createStatement(int, int) method creates a
Statement object)
page 929: 3rd sentence in last paragraph
A wrong class name is used: a
ResultSet is created using a
Statement (not a
ResultSet).
Currently: when a
Statement is closed, any
ResultSet created using that
ResultSet is also closed
Should be: when a
Statement is closed, any
ResultSet created using that
Statement is also closed
page 940: Self Test, Question 10
Answer D uses a wrong variable name in its code.
Currently:
numbBooks = rs.getInt(1);
Should be:
numBooksRemoved = rs.getInt(1);
page 940: Self Test, Question 11
Answer D uses a wrong method name in its code.
Currently:
RowSet rws = rsf.createRowSet();
Should be:
RowSet rws = rsf.createJdbcRowSet();
OCA Mock Exams on CD (question numbers when not in randomized mode)
objective 8.0: Question 9 (about exceptions thrown by developers)
The exceptions of the correct answers are runtime exceptions (not checked exceptions).
Currently: B, C, and D are (correct), examples of
checked exceptions.
Should be: B, C, and D are (correct), examples of
runtime exceptions
thrown by an application developer or an API developer.
OCP Mock Exams on CD (question numbers when not in randomized mode)
objective 1.0: Question 2 (class BioDiesel)
The explanation is mainly explaining why line
#2 is correct, not why line
#1 results in a compiler error.
Currently: Only instance methods can be overridden, and calls to
super only apply to overridden methods.
Should be: Only instance methods can be overridden, and calls to
super only apply to overridden methods. So
super can only be used in an instance context, not in a static context.
objective 1.0: Question 4 (class Putter)
The question asks to select the statements which will NOT compile, but the correct answers are the statements which will compile successfully. So
NOT should be removed from the question (or the correct answers should be changed to A and E).
Currently: Which, inserted at
// insert code, will
NOT compile?
Should be: Which, inserted at
// insert code, will compile?
objective 3.0: Question 3 (about IS-A relationships)
An IS-A relationship can also occur between at least two interfaces or a class and an interface or an enum and an interface.
Currently:
C. IS-A relationships always require at least two
class types
Should be:
C. IS-A relationships always require at least two types
objective 3.0: Question 4 (about HAS-A relationships)
An HAS-A relationship can also rely on class variables. (Confirmed in the explanation of question 11 of this objective)
Currently:
B. HAS-A relationships always rely on instance variables
Should be:
B. HAS-A relationships always rely on
class or instance variables
objective 6.0: Question 6 (about assertions)
The explanation about answer E is incorrect. Explicitly throwing an
AssertionError is sometimes
an acceptable alternative. Another alternative can be found in
this post.
Currently: throwing an
AssertionError explicitly is considered
bad practice
Should be: throwing an
AssertionError explicitly is considered
to be sometimes an acceptable alternative (e.g. a switch statement with no default case)
objective 6.0: Question 10 (class S)
The explanation is spot-on, but there's a slip-up in the correct answers. C and D are the correct answers.
Currently:
-
B and D are correct.
- A,
C, E, and F are incorrect because of the above.
Should be:
-
C and D are correct.
- A,
B, E, and F are incorrect because of the above.
The end!
CategoryCertification