Errata
Please check here often as we will update the errata regularly.
You can either contact us directly (Khalid, Vasily) to report an error or you can post it on the PROGRAMMER CERTIFICATION (OCPJP) FORUM at Coderanch.
On the forum, just create a new thread and designate the subject to be "OCP Java 17 Programmer's Guide", together with the page number in the book.
We monitor the forum for any feedback.
Errata updates:
| Date of update | Printing | Pages |
|---|---|---|
| 2023-04-20 | 1st | 1198 |
| 2023-05-09 | 1st | 1677 |
| 2023-07-16 | 1st | 29 |
| 2023-07-21 | 1st | 238 |
| 2023-08-07 | 1st | 516, 525, 526 |
| 2023-08-08 | 1st | 518 |
| 2023-08-25 | 1st | 1501 |
| 2023-09-04 | 1st | 943 |
| 2023-09-16 | 1st | 1071 |
| 2023-11-20 | 1st | 14, 22, 27, 1636 |
| 2024-01-02 | 1st | 22, 25 |
| 2024-03-05 | 1st | 1648 |
| 2024-07-22 | 1st | 216, 237 |
| 2024-11-16 | 1st | 30, 31, 32, 75 |
| 2024-11-29 | 1st | 108, 110, 114, 115, 134, 1641 |
| 2024-12-26 | 1st | 162, 180 |
| 2025-02-04 | 1st | 267 |
| 2025-02-16 | 1st | 99, 100 |
| 2025-02-20 | 1st | 193, 197, 202, 204, 206 |
| 2025-02-22 | 1st | 212, 219, 222, 225, 226 |
| 2025-02-24 | 1st | 226, 231, 232, 233 |
| 2025-02-26 | 1st | 238, 240, 244, 246, 251, 252, 255 |
| 2025-02-28 | 1st | 266, 276, 290, 293, 300 |
| 2025-03-01 | 1st | 301, 302, 303 |
| 2025-03-07 | 1st | 310, 311, 312, 1647 |
| 2025-06-25 | 1st | 324, 325, 328, 329, 330, 332, 345, 347, 352, 360 |
Acknowledgements:
Many thanks to the following readers for their diligent observations: Eric Borm, Valerio Cesolani, Michael Gualeni, Tinashe Muchada, Satish Singh, Ivan Titov.
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 14
1st printing, start of the last-but-one paragraph:
CHANGE:
It addition, the Point3D class...
TO:
In addition, the Point3D class...
Page 22
1st printing, replace the paragraph:
CHANGE:
Unlike the javac command, the name of the single source file (e.g., Demo-App.java) need not be a valid class name, but it must have the .java extension. Also unlike the javac command, the java command allows several public classes in the single source file (only public classes in the Demo-App.java file).
TO:
The name of the single source file (e.g., Demo-App.java) need not be a valid class name, but it must have the .java extension. Unlike the javac command, the java command allows several public classes in the single source file (only public classes in the Demo-App.java file).
1st printing, the third bullet should be deleted:
DELETE:
There must not exist class files corresponding to the class declarations in the single source file that are accessible by the java command.
Page 25
1st printing, at the end of the last paragraph:
INSERT:
Note that if a value is wider than the width specified in the format, then the width in the format is ignored.
Page 27
1st printing, in the review question 1.9:
CHANGE:
Select the one correct answer.
TO:
Select the two correct answers.
Page 29
1st printing, under Chapter Topics in Chapter 2, the word "boolean" is misspelt in the following bullet:
CHANGE:
Overview of primitive data types defined in Java: integral, floating-point, and boolgean
TO:
Overview of primitive data types defined in Java: integral, floating-point, and boolean
Page 30
1st printing, in subsection Identifiers:
CHANGE:
a keyword (Table 2.1, p.31)
TO:
a reserved keyword (Table 2.3, p.32)
Page 31
1st printing, in Table 2.1:
DELETE:
_ (underscore)
Page 32
1st printing, in Table 2.3:
INSERT:
_ (underscore)
Page 75
1st printing, at the end of section Relational Operators: <, <=, >, >=:
CHANGE:
Relational operators are nonassociative.
TO:
Although the relational operators are defined as left associative, this fact cannot be exploited.
CHANGE:
Since relational operators have left associativity, the evaluation ...
TO:
The evaluation ...
Page 99
1st printing, in Section 3.1, Class Declarations:
CHANGE:
class_modifiers class class_name extends_clause implements_clause
TO:
optional_class_modifiers class class_name optional_type_parameter_list optional_extends_clause optional_implements_clause
1st printing, in Section 3.1, Class Declarations, insert after first bullet:
INSERT:
Type parameters are defined for generic classes (§11.2, p. 567)
Page 100
1st printing, in Section 3.2, Method Declarations:
CHANGE:
method_modifiers return_type method_name
(formal_parameter_list) throws_clause // Method header
TO:
optional_method_modifiers optional_type_parameter_list return_type method_name
(optional_formal_parameter_list) optional_throws_clause // Method header
1st printing, in Section 3.2, Method Declarations, insert after first bullet:
INSERT:
Type parameters are defined for generic methods (§11.7, p. 593)
Page 108
1st printing, in section 3.5:
CHANGE:
The hash code of an object is an int value that uniquely identifies the object.
TO:
The hash code of an object is an int value that ideally identifies the object.
1st printing, in section 3.6, delete the 'j':
CHANGE:
methodA(int)j 1' 2': Number of parameters
TO:
methodA(int) 1' 2': Number of parameters
Page 110
1st printing, insert the following at the end of the last sentence in the second paragraph of the subsection The Default Constructor:
INSERT:
... or in an initialization block (§10.8, p.551)
Page 114
1st printing, in subsection Static Fields in Classes, change the name of the method:
CHANGE:
The print statement at (2) in the static method printCount() shows ...
TO:
The print statement at (2) in the static method printStatic() shows ...
Page 115
1st printing, in subsection Static Methods in Classes, change the name of the method:
CHANGE:
Example 3.6 shows how the static method printCount() of the class Light ...
TO:
Example 3.6 shows how the static method printStatic() of the class Light ...
Page 134
1st printing, towards the end of the subsection Passing Arrays:
CHANGE:
... will result in the swap() method at (3) to be invoked.
TO:
... will result in the swap() method at (3) being invoked.
1st printing, in the last sentence at the end of the subsection Passing Arrays:
INSERT:
... , as in the calls to the printIntArray() method in the main() method.
Page 162
1st printing, in subsection Using Strings as case Constants, change the line number:
CHANGE:
From the declaration at (2a), the compiler cannot guarantee that the value of the reference will not change at runtime.
TO:
From the declaration at (2b), the compiler cannot guarantee that the value of the reference will not change at runtime.
Page 180
1st printing, in section Labeled Statements, at the end of the section:
CHANGE:
A labeled statement is executed as if it were unlabeled, unless it is the break or continue statement.
TO:
A labeled statement is executed as if it were unlabeled, unless its label is the target label of a break or a continue statement.
Page 193
1st printing, first paragraph, last sentence, delete the clause:
CHANGE:
Multiple inheritance of implementation occurs when a class inherits multiple implementations from the interfaces it implements, but this is not allowed in Java (p. 240).
TO:
Multiple inheritance of implementation occurs when a class inherits multiple implementations from the interfaces it implements (p. 240).
Page 197
1st printing, second paragraph, last sentence:
CHANGE:
The criteria for overriding methods also apply to interfaces, where a subinterface can override abstract and default method declarations from its superinterfaces (p. 237).
TO:
The criteria for overriding methods also apply to interfaces, where a subinterface or a class implementing interfaces can override abstract and default method declarations from its superinterfaces (p. 237).
Page 202
1st printing, last sentence:
CHANGE:
In contrast, both nonprivate instance and static methods can be overloaded in the class they are defined in or are in a subclass of the class they are defined in.
TO:
In contrast, both instance and static methods can be overloaded in the class they are defined in or in a subclass of the class they are defined in, provided they are accessible from the subclass using their simple name.
Page 204
1st printing, last bullet:
CHANGE:
Declare constructors that can invoke constructors in the superclass implicitly, or use the super() construct with the appropriate arguments to invoke them explicitly (p. 209)
TO:
Declare constructors that can invoke the no-argument constructor in the superclass implicitly, or use the super() construct with the appropriate arguments to invoke constructors in the superclass explicitly (p. 209)
Page 206
1st printing, third paragraph:
CHANGE:
Method invocation is determined by the class of the current object, resulting in the inherited method energyCost() in the class TubeLight being executed.
TO:
Method invocation is determined by the class of the current object, resulting in the overridden method energyCost() in the class TubeLight being executed.
1st printing, insert this paragraph at the end of the page:
INSERT:
A default method foo() in interface II can be accessed using the keyword super: II.super.foo();
Page 212
1st printing, first paragraph, second sentence:
CHANGE:
Although the constructor is not strictly necessary, as the compiler will insert one—as explained later—it is included here for expositional purposes.
TO:
Although the constructor call is not strictly necessary, as the compiler will insert one—as explained later—it is included here for expositional purposes.
Page 216
1st printing, in Review Question 5.3:
CHANGE:
class A { int max(int x, int y) { (x>y) ? x : y; } }
TO:
class A { int max(int x, int y) { return (x>y) ? x : y; } }
Page 219
1st printing, bottom of the page:
CHANGE:
A class that is declared absract cannot be instantiated, ...
TO:
A class that is declared abstract cannot be instantiated, ...
Page 222
1st printing, second paragraph, delete the clause:
CHANGE:
The PostModernMinimalistArt class at (5) is declared abstract and considered incomplete, even though it is concrete.
TO:
The PostModernMinimalistArt class at (5) is declared abstract and considered incomplete.
Page 225
1st printing, in the middle of the page:
CHANGE:
... // Not overloaded! Duplicate method!
TO:
... // Not overridden! Incompatible return type Double!
Page 226
1st printing, top of the page:
CHANGE:
A concrete class is a class that has only concrete methods--
TO:
A concrete class is a class that has only concrete methods, also those that are inherited--
1st printing, second paragraph:
CHANGE:
A final class and an interface with only abstract methods represent two diametrical strategies ...
TO:
A final class and an interface or an abstract class with only abstract methods represent two diametrically opposite strategies ...
Page 231
1st printing, bottom half of the page:
CHANGE:
The non-final local reference carLight at (22) also cannot be accessed at (22) before it is initialized.
TO:
The non-final local reference carLight at (22) also cannot be accessed at (23) before it is initialized.
Page 232
1st printing, in subsection Definite Assignment Analysis for Final Variables, second paragraph, change "any" to "every":
CHANGE:
This involves checking whether a blank final variable has been assigned a value on any possible path of execution to where the value of the variable is accessed.
TO:
This involves checking whether a blank final variable has been assigned a value on every possible path of execution to where the value of the variable is accessed.
Page 233
1st printing, last paragraph, change (3) to (1):
CHANGE:
If the code is modified by replacing the if statement at (3) with an if-else statement, ...
TO:
If the code is modified by replacing the if statement at (1) with an if-else statement, ...
Page 237
1st printing, in Review Question 5.16, for class Animal:
CHANGE:
public static final MAX_SIZE = 10;
TO:
public static final int MAX_SIZE = 10;
Page 238
1st printing, second paragraph, last sentence:
DELETE:
As we shall also see, multiple inheritance of type does not pose any problems, but multiple inheritance of implementation does and is disallowed by the compiler.
1st printing, in the section Defining Interfaces:
CHANGE:
The access modifier can be public or private. Lack of an access modifier implies package accessibility.
TO:
The access modifier can be public. Lack of an access modifier implies package accessibility.
Page 240
1st printing, top of the page:
CHANGE:
return_type method_name (formal_parameter_list) throws_clause;
TO:
return_type method_name (optional_formal_parameter_list) optional_throws_clause;
1st printing, top of the page:
CHANGE:
Note that an abstract method is an instance method whose implementation will be provided by a class that implements the interface in which the abstract method is declared.
TO:
Note that an abstract method is an instance method whose implementation will be provided by a default method in a sub-interface or a class that implements the interface in which the abstract method is declared.
Page 244
1st printing, bottom of the page:
CHANGE:
Realization is depicted in a similar manner to extending classes, but is indicated by an unbroken inheritance arrow.
TO:
Realization is depicted in a similar manner to extending classes, but is indicated by a dotted inheritance arrow.
Page 246
1st printing, middle of the page:
CHANGE:
default return_type method_name (formal_parameter_list) throws_clause
TO:
default return_type method_name (optional_formal_parameter_list) optional_throws_clause
Page 251
1st printing, middle of the page:
CHANGE:
static return_type method_name (formal_parameter_list) throws_clause
TO:
static return_type method_name (optional_formal_parameter_list) optional_throws_clause
Page 252
1st printing, change "duplicity" to "duplication":
CHANGE:
They allow code to be shared between the non-abstract methods in the interface, thus promoting code reuse and avoiding code duplicity.
TO:
They allow code to be shared between the non-abstract methods in the interface, thus promoting code reuse and avoiding code duplication.
Page 255
1st printing, change (2) to (3):
CHANGE:
The declaration of the constant BLOCKED at (6) in the interface IAllStates hides the declaration of the constant at (2) in the interface IBaseStates.
TO:
The declaration of the constant BLOCKED at (6) in the interface IAllStates hides the declaration of the constant at (3) in the interface IBaseStates.
Page 266
1st printing, top of the page:
CHANGE:
One method is considered more specific than another method if all actual parameters that can be accepted by the one method can be accepted by the other method.
TO:
One method is considered no more specific than another method if all actual parameters that can be accepted by the one method can be accepted by the other method.
Page 267
1st printing, in Example 5.19:
CHANGE:
System.out.println(client.testIfOn(light2)); // (5) ==> method at (2)
TO:
System.out.println(client.testIfOn(light2)); // (5) ==> method at (1)
Page 276
1st printing, bottom of the page:
CHANGE:
IStack stack = new SafeStack(
TO:
IStack stack = new SafeStack(50);
Page 290
1st printing, in Example 5.24, in comment (6):
CHANGE:
contants
TO:
constants
Page 293
1st printing, last but one paragraph:
CHANGE:
Comparing two enum references for equality meanss determining ...
TO:
Comparing two enum references for equality means determining ...
Page 300
1st printing, Example 5.27, declaration of equals() method:
CHANGE:
&& this.year == other.year
TO:
&& this.year.equals(other.year)
Page 301
1st printing, top of the page, class name "CD_v0" should be "CD_v1":
CHANGE:
The CD_v0 class in Example 5.27 can be declared as a record class, as shown in Example 5.28.
TO:
The CD_v1 class in Example 5.27 can be declared as a record class, as shown in Example 5.28.
1st printing, top of the page, "contructor" should be "constructor":
CHANGE:
The compiler automatically generates the necessary fields, contructor, ...
TO:
The compiler automatically generates the necessary fields, constructor, ...
Page 302
1st printing, first bullet, end of first paragraph, class name "CD_v0" should be "CD_v1":
CHANGE:
The component fields in the CD record class are equivalent to the instance field declarations in the CD_v0 class in Example 5.27.
TO:
The component fields in the CD record class are equivalent to the instance field declarations in the CD_v1 class in Example 5.27.
1st printing, second bullet, end of last paragraph, class name "CD_v0" should be "CD_v1":
CHANGE:
Although their names are different, the get methods of the CD record class are equivalent to the get methods of the CD_v0 class in Example 5.27.
TO:
Although their names are different, the get methods of the CD record class are equivalent to the get methods of the CD_v1 class in Example 5.27.
Page 303
1st printing, top of the page, class name "CD_v0" should be "CD_v1":
CHANGE:
The implementation of the implicit canonical constructor for the CD record class is equivalent to the non-zero argument normal constructor implemented in the CD_v0 class in Example 5.27.
TO:
The implementation of the implicit canonical constructor for the CD record class is equivalent to the non-zero argument normal constructor implemented in the CD_v1 class in Example 5.27.
1st printing, second bullet, class name "CD_v0" should be "CD_v1":
CHANGE:
... —analogous to the implementation of the equals() method in the CD_v0 class in Example 5.27.
TO:
... —analogous to the implementation of the equals() method in the CD_v1 class in Example 5.27.
1st printing, last bullet, class name "CD_v0" should be "CD_v1":
CHANGE:
... —analogous to the implementation of the hashCode() method in the CD_v0 class in Example 5.27.
TO:
... —analogous to the implementation of the hashCode() method in the CD_v1 class in Example 5.27.
Page 310
1st printing, subsection Implementing Interfaces:
CHANGE:
As a record class is implicitly final, it cannot extend other classes.
TO:
As a record class implicitly extends the java.lang.Record abstract class, it cannot extend other classes.
Page 311
1st printing, subsection Generic Record Classes:
CHANGE:
Generic record classes can be delcared, ...
TO:
Generic record classes can be declared, ...
1st printing, middle of the page:
CHANGE:
Also, their immutability provides thread safety in concurrent applications.
TO:
Records are shallowly immutable, but can provide thread safety in concurrent applications if their fields are also immutable.
Page 312
1st printing, subsection Sealed Classes, third paragraph, last sentence:
CHANGE:
Skeletal code for the classes in shown ...
TO:
Skeletal code for the classes is shown ...
Page 324
1st printing, second bullet, first sentence:
CHANGE:
(class, enum type, interface)
TO:
(be it a class, a record, an enum type, or an interface)
1st printing, last bullet, last sentence:
CHANGE:
Inter-package accessibility of types can be controlled through public or package accessibility (p. 347).
TO:
Inter-package accessibility of top-level reference types can be controlled through public or package accessibility (p. 347).
Page 325
1st printing, item number 3, first paragraph, second sentence:
CHANGE:
Class, enum, and interface declarations are collectively known as type declarations.
TO:
Class, enum, records, and interface declarations are collectively known as type declarations.
1st printing, item number 3, first paragraph, last sentence:
CHANGE:
Since these declarations belong to the same package, they are said to be defined at the top level, which is the package level.
TO:
Since none of these declarations are nested in another type declaration, they are said to be defined at the top level, which is the package level.
1st printing, item number 3, last paragraph:
CHANGE:
Classes are discussed in §3.1, p. 99; interfaces are discussed in §5.6, p. 239; and enums are discussed in §5.13, p. 289.
TO:
Classes are discussed in §3.1, p. 99; interfaces are discussed in §5.6, p. 239; enums are discussed in §5.13, p. 289; records are discussed in §5.14, p. 301.
Page 328
1st printing, section Defining Packages, first paragraph, last sentence:
CHANGE:
A type declaration can indicate ...
TO:
A source file can indicate ...
Page 329
1st printing, subsection Importing Reference Types, first sentence:
CHANGE:
(classes, interfaces, and enums)
TO:
(classes, interfaces, enums, and records)
Page 330
1st printing, top of the page, second sentence:
CHANGE:
the classes Clown and LovePotion and the interface Magic that are ...
TO:
the classes Clown and LovePotion that are ...
1st printing, top of the page, second sentence:
CHANGE:
It allows any type from the specified package to be accessed by its simple name.
TO:
It allows any accessible type from the specified package to be accessed by its simple name.
Page 332
1st printing, paragraph before Example 6.3, second sentence:
CHANGE:
The static import statement at (1) allows the interface constants in the package mypkg to be accessed by their simple names.
TO:
The static import statement at (1) allows the constants of the IMachineState interface in the package mypkg to be accessed by their simple names.
Page 345
1st printing, section Access Modifiers for Top-Level Type Declarations, first sentence:
CHANGE:
The access modifier public can be used ...
TO:
In named packages, the access modifier public can be used ...
Page 347
1st printing, paragraph before Table 6.2, first sentence:
CHANGE:
Table 6.2 summarizes accessibility of top-level reference types in a package.
TO:
Table 6.2 summarizes accessibility of top-level reference types in a named package.
1st printing, section Access Modifiers for Class Members, first sentence:
CHANGE:
(i.e., other classes)
TO:
(i.e., other types)
Page 352
1st printing, subsection Additional Remarks on Accessibility, last paragraph, before paragraph reference:
INSERT:
, barring any private methods defined in the interface
Page 360
1st printing, second sentence:
CHANGE:
Such a class cannot be instantiated and has no state, and is thus immutable.
TO:
Such a class is not meant to be instantiated or extended, and typically has a private constructor and no state, and is thus immutable.
Page 516
1st printing, in the last sentence, the name of the non-static field should be nsf2 and not nsf1:
CHANGE:
The static field sf in the class TLCWith2LCS is accessed in the StaticLocal class at (14), but the non-static field nsf1 cannot be accessed, as shown at (13).
TO:
The static field sf in the class TLCWith2LCS is accessed in the StaticLocal class at (14), but the non-static field nsf2 cannot be accessed, as shown at (13).
Page 518
1st printing, in the output from Example 9.12:
CHANGE:
Painter$1$Circle
Painter$1$Graph
TO:
Painter$1Circle
Painter$1Graph
Page 525
1st printing, the second sentence in the subsection Accessing Local Declarations in the Enclosing Block:
CHANGE:
An anonymous class can only access (effectively) final variables in its enclosing local context, shown both for static fields at (10), (11), and (12), and for instance fields at (13), (14), and (15).
TO:
Local variables in the enclosing non-static method cannot be accessed in any static fields of an anonymous class, whether they are (effectively) final or not, as shown at (10), (11), and (12). An anonymous class can only access (effectively) final local variables in its enclosing local context from its instance fields, as shown at (13), (14), and (15).
Page 526
1st printing, in Example 9.15 (see the new explanation on page 525):
CHANGE:
static int sff1 = fp; // (10) Final param from enclosing method
static int sff2 = flv; // (11) Effect. final variable from enclosing method
TO:
// static int sff1 = fp; // (10) Final param from enclosing method // static int sff2 = flv; // (11) Effect. final variable from enclosing method
Page 943
1st printing, in the subsection Querying an Optional:
CHANGE:
<X extends Throwable> T orElseThrow(Supplier<? extends X> exceptionSupplier) throws X extends Throwable
TO:
<X extends Throwable> T orElseThrow(Supplier<? extends X> exceptionSupplier) throws X
Page 1071
1st printing, in Example 17.7, logical error in the loop condition of the for(;;) loop:
CHANGE:
time.plus(duration).isBefore(endTimeExclusive);
TO:
time.isBefore(endTimeExclusive);
1st printing, in Example 17.7, the program output is missing a showtime:
CHANGE:
Showtime (PT2H15M): 10:10
Showtime (PT2H15M): 12:25
Showtime (PT2H15M): 14:40
Showtime (PT2H15M): 16:55
Showtime (PT2H15M): 19:10
Closing time: 23:00
TO:
Showtime (PT2H15M): 10:10
Showtime (PT2H15M): 12:25
Showtime (PT2H15M): 14:40
Showtime (PT2H15M): 16:55
Showtime (PT2H15M): 19:10
Showtime (PT2H15M): 21:25
Closing time: 23:00
Page 1198
1st printing, in Figure 19.15:
CHANGE:
«module game»
TO:
«module name»
Page 1501
1st printing, in Figure 23.7:
CHANGE:
CopyOnWriteArrayList<K,V>
CopyOnWriteArraySet<K,V>
TO:
CopyOnWriteArrayList<E>
CopyOnWriteArraySet<E>
Page 1636
1st printing, option (c) is also correct for the review question 1.9:
CHANGE:
(a)
TO:
(a) and (c)
1st printing, in the annotated answer to the review question 1.9, the last sentence is not correct:
CHANGE:
Since it is specified that the source file is compiled creating a class file, (c) would not work.
TO:
It does not matter whether the source file has already been compiled, (c) will still work as the SmallProg.java file has the class definition.
Page 1641
1st printing, annotated answer to the review question 3.13, in middle of the explanation:
CHANGE:
(a), (b), and (c) are fixed arity calls.
TO:
(a), (b), and (c) are variable arity calls.
Page 1647
1st printing, review question 5.22:
CHANGE:
5.22 (b) The compiler will allow the statement, as the cast is from the supertype (Super) to the subtype (Sub). However, if at runtime the reference x does not denote an object of the type Sub, a ClassCastException will be thrown.
TO:
5.22 (d) It is definitely legal at runtime, and the cast operator (Sub) is needed.
Page 1648
1st printing, add to the explanation for Review Question 5.27:
INSERT:
Compiling the options in Eclipse with JDK 17 will not result in compile-time errors for (a), (b), and (e). Seems to be a bug. However, compiling the code on the command line with javac for JDK 17 will print errors that will back the explanation for the review question.
Page 1677
1st printing, answer to Review Question 15.20:
CHANGE:
(b)
TO:
(a)
