Susan Harkins (223) [Avatar] Offline
#1
Please post errors in the published version of OCA Java SE 8 Programmer I Certification Guide here. We'll publish a comprehensive list for everyone's convenience. Thank you!

Susan Harkins
Errata Editor
Manning Publications
428299 (1) [Avatar] Offline
#2
Hi,
In page 416, figure 6.16 "What happens when you change an abstract method in an interface to a default or static method", please, read my comment in line 14 of the code.

interface Jumpable {
static int maxDistance() {
return 200;
}
}
class Animal implements Jumpable {}
public int maxDistance() {
return 100;
}
}
class Forest {
public static void main(String args[]) {
Animal lion = new Animal();
System.out println(lion.maxDistance()); // ERROR: in the book says that this code "Doesn't compile", but it compiles because we still have the method maxDistance in Animal class.
}
}


The above code compiles. The below code won't compile, because we have removed the method maxDistance() in Animal class. This way:

interface Jumpable {
static int maxDistance() {
return 200;
}
}
class Animal implements Jumpable {}
//Removing this code because the method is static, then it is optional to have the method maxDistance here.
/*public int maxDistance() {
return 100;
}*/ 
}
class Forest {
public static void main(String args[]) {
Animal lion = new Animal();
System.out println(lion.maxDistance()); //Now, because we are refering tho "maxDistance" using the class Animal, the code "Doesn't compile".
}
}


I think the book wanted to explain the second option (showing a compilation error) and it forgot to remove the maxDistance from class Animal.

Please, correct me if I am wrong.

Thanks.

Daniel Augusto de Alcântara Neto (4) [Avatar] Offline
#3
Interface with private member? - Private access modifier - section 1.4.5
Susan Harkins wrote:Please post errors in the published version of OCA Java SE 8 Programmer I Certification Guide here. We'll publish a comprehensive list for everyone's convenience. Thank you!

Susan Harkins
Errata Editor
Manning Publications

Previous, I wrote a post with the same question, but latter i see this post. I am sorry for duplicated post.

In the book (section 1.4.5 - page 61), is written:

"private members are acessible only to the classes and interfaces in which they're defined."

My question is: interfaces can have private member? This is correct?
Daniel Augusto de Alcântara Neto (4) [Avatar] Offline
#4
Example with wrong name of parameter
In the page 132, there is a code:


public int increment (Integer obj) {
   return ++i;
}


The correct is (change name of parameter obj to i):
public int increment (Integer i) {
   return ++i;
}


Or this (change name of variable i to obj):

public int increment (Integer obj) {
   return ++obj;
}
Christopher Kaufmann (1) [Avatar] Offline
#5
Message received from a customer on Facebook regarding an error:

Location: Chapter 4, page 238.

Photo indicating mistake is in the attachment.

Cheers
443739 (1) [Avatar] Offline
#6
Mock Exam Q40. Explanation on page 609. Option c is indicated as correct. Option c is not correct, there are only two correct options, not three.

c. Jump[] eJump3 = new Jump[10];
d. Jump[] eJump4 = new Animal[87];
e. Jump[] eJump5 = new Jump()[12];

...

"Option (e) is incorrect. Apart from using an invalid syntax to initialize an array (as mentioned previously), it also tries to create objects of the interface Jump. Objects of interfaces can't be created."

This same logic applies to option c. You cannot create objects of type Jump because it is an interface. Option c cannot be correct.
AndreiT17 (2) [Avatar] Offline
#7
Hi,

I am new to this forum and I try to remember java programming from while a go (around 12 years...), since I left programming altogether, so I apologize if the question is off topic, or if it does not make sense. I also bought the ebook version of the book, so I am not able to locate the page number.

Anyways, my question is about a statement in section 4.4.6, specifically "Adding multiple elements to an ArrayList", just before/above the Exam Tip:
<blockquote>What happens if you modify the common object references in these lists, myArrList and yourArrList? We have two cases here: in the first one, you reassign the object reference using either of the lists. In this case, the value in the second list will remain unchanged. In the second case, you modify the internals of any of the common list elements—in this case, the change will be reflected in both of the lists.<blockquote>
I understand the first part of this statement, but I don't understand the second part (second case). It looks like even if I change an element in yourArrList (formerly added to the myArrList) this is not reflected in myArrayList (which contains also yourArrList). Please somenone help me understand what do I miss. Below extract of code and output:
Code:
=====
ArrayList<StringBuilder> myArrList = new ArrayList<StringBuilder>();
myArrList.add(new StringBuilder("One"));
myArrList.add(new StringBuilder("Two"));
ArrayList<StringBuilder> yourArrList = new ArrayList<StringBuilder>();
yourArrList.add(new StringBuilder("Three"));
yourArrList.add(new StringBuilder("Four"));
myArrList.addAll(yourArrList);
System.out.println("After adding yourArrList to myArrList");
System.out.println("myArrList:");
for(StringBuilder sb:myArrList){
System.out.println(sb);
}
System.out.println("yourArrList:");
for(StringBuilder sb:yourArrList){
System.out.println(sb);
}

System.out.println("Modify the internal of yourArrList and see what happens with myArrList which contains now yourArrlist");
yourArrList.set(1, new StringBuilder("Ten"));

System.out.println("myArrList:");
for(StringBuilder sb:myArrList){
System.out.println(sb);
}
System.out.println("yourArrList:");
for(StringBuilder sb:yourArrList){
System.out.println(sb);
}

========================================
Output:
======
After adding yourArrList to myArrList
myArrList:
One
Two
Three
Four
yourArrList:
Three
Four
Modify the internal of yourArrList and see what happens with myArrList which contains now yourArrlist
myArrList:
One
Two
Three
Four
yourArrList:
Three
Ten
===========================================

As you can see, myArrList did not change.

Thanks,

Andrei

mala.gupta (244) [Avatar] Offline
#8
Example with wrong name of parameter
Daniel Augusto de Alcântara Neto wrote:In the page 132, there is a code:


public int increment (Integer obj) {
   return ++i;
}


The correct is (change name of parameter obj to i):
public int increment (Integer i) {
   return ++i;
}


Or this (change name of variable i to obj):

public int increment (Integer obj) {
   return ++obj;
}


Thanks for reporting it Daniel. You are correct.

I've added it to the book's errata.

With much respect,
Mala
mala.gupta (244) [Avatar] Offline
#9
AndreiT17 wrote:Hi,

I am new to this forum and I try to remember java programming from while a go (around 12 years...), since I left programming altogether, so I apologize if the question is off topic, or if it does not make sense. I also bought the ebook version of the book, so I am not able to locate the page number.

Anyways, my question is about a statement in section 4.4.6, specifically "Adding multiple elements to an ArrayList", just before/above the Exam Tip:
<blockquote>What happens if you modify the common object references in these lists, myArrList and yourArrList? We have two cases here: in the first one, you reassign the object reference using either of the lists. In this case, the value in the second list will remain unchanged. In the second case, you modify the internals of any of the common list elements—in this case, the change will be reflected in both of the lists.<blockquote>
I understand the first part of this statement, but I don't understand the second part (second case). It looks like even if I change an element in yourArrList (formerly added to the myArrList) this is not reflected in myArrayList (which contains also yourArrList). Please somenone help me understand what do I miss. Below extract of code and output:
Code:
=====
ArrayList<StringBuilder> myArrList = new ArrayList<StringBuilder>();
myArrList.add(new StringBuilder("One"));
myArrList.add(new StringBuilder("Two"));
ArrayList<StringBuilder> yourArrList = new ArrayList<StringBuilder>();
yourArrList.add(new StringBuilder("Three"));
yourArrList.add(new StringBuilder("Four"));
myArrList.addAll(yourArrList);
System.out.println("After adding yourArrList to myArrList");
System.out.println("myArrList:");
for(StringBuilder sb:myArrList){
System.out.println(sb);
}
System.out.println("yourArrList:");
for(StringBuilder sb:yourArrList){
System.out.println(sb);
}

System.out.println("Modify the internal of yourArrList and see what happens with myArrList which contains now yourArrlist");
yourArrList.set(1, new StringBuilder("Ten"));

System.out.println("myArrList:");
for(StringBuilder sb:myArrList){
System.out.println(sb);
}
System.out.println("yourArrList:");
for(StringBuilder sb:yourArrList){
System.out.println(sb);
}

========================================
Output:
======
After adding yourArrList to myArrList
myArrList:
One
Two
Three
Four
yourArrList:
Three
Four
Modify the internal of yourArrList and see what happens with myArrList which contains now yourArrlist
myArrList:
One
Two
Three
Four
yourArrList:
Three
Ten
===========================================

As you can see, myArrList did not change.

Thanks,

Andrei



Hi Andrei -

Thanks for posting this issue.

I've posted a response to this query in your initial thread - https://forums.manning.com/posts/list/40232.page

Apologies for the delay in responding.

With much respect,
Mala
mala.gupta (244) [Avatar] Offline
#10
428299 wrote:Hi,
In page 416, figure 6.16 "What happens when you change an abstract method in an interface to a default or static method", please, read my comment in line 14 of the code.

interface Jumpable {
static int maxDistance() {
return 200;
}
}
class Animal implements Jumpable {}
public int maxDistance() {
return 100;
}
}
class Forest {
public static void main(String args[]) {
Animal lion = new Animal();
System.out println(lion.maxDistance()); // ERROR: in the book says that this code "Doesn't compile", but it compiles because we still have the method maxDistance in Animal class.
}
}


The above code compiles. The below code won't compile, because we have removed the method maxDistance() in Animal class. This way:

interface Jumpable {
static int maxDistance() {
return 200;
}
}
class Animal implements Jumpable {}
//Removing this code because the method is static, then it is optional to have the method maxDistance here.
/*public int maxDistance() {
return 100;
}*/ 
}
class Forest {
public static void main(String args[]) {
Animal lion = new Animal();
System.out println(lion.maxDistance()); //Now, because we are refering tho "maxDistance" using the class Animal, the code "Doesn't compile".
}
}


I think the book wanted to explain the second option (showing a compilation error) and it forgot to remove the maxDistance from class Animal.

Please, correct me if I am wrong.

Thanks.



Hi there -

Thanks for reporting this issue.

You are correct. I've added it to the book's errata.

With much respect,
Mala
mala.gupta (244) [Avatar] Offline
#11
443739 wrote:Mock Exam Q40. Explanation on page 609. Option c is indicated as correct. Option c is not correct, there are only two correct options, not three.

c. Jump[] eJump3 = new Jump[10];
d. Jump[] eJump4 = new Animal[87];
e. Jump[] eJump5 = new Jump()[12];

...

"Option (e) is incorrect. Apart from using an invalid syntax to initialize an array (as mentioned previously), it also tries to create objects of the interface Jump. Objects of interfaces can't be created."

This same logic applies to option c. You cannot create objects of type Jump because it is an interface. Option c cannot be correct.


Hi there -

The option (c) isn't trying to instantiate the interface Jump (the new operator is not called). The code is stating that this array will store upto 10 instances of classes that implement the interface Jump.

Thanks.

With much respect,
Mala
Susan Harkins (223) [Avatar] Offline
#12
475376 (18) [Avatar] Offline
#13
Part of the explanation of the answer A.2.5 Twist in the Tale 2.4 is incorrect.

Toward the bottom of page 646, the author correctly explains that because of operator precedence the expression is evaluated as (a >= 99 || (a <= 33 && b == 10)). However, the subsequent explanation of how that expression is evaluated is incorrect (last paragraph of page 646 though the beginning of page 647).

According to the book, "Evaluation of the preceding expression starts with the evaluation of (a <= 33 && b == 10)" and the original expression reduces to (a >= 99 || false).

In truth, evaluation of the expression starts with evaluation of the first operand of the short-circuit OR operator, the expression a >= 99. It is only because a >= 99 evaluates to false that the second operand of the short-circuit OR operator, the expression (a <= 33 && b == 10), is (then subsequently) evaluated.
475376 (18) [Avatar] Offline
#14
On page 193, the line

Class Test {

should read

class Test {
475376 (18) [Avatar] Offline
#15
Page 283 EXAM TIP states,
If you don't pass a DateTimeFormatter, the format of the string passed to parse() must be exactly of the format 99:99:99.

No, it doesn't have to be exactly that. Specifying the seconds is optional. Also, nanoseconds can be specified, by following the seconds with a decimal point and one to nine digits. Strings of "10:15", "10:15:30", and "10:15:30.512345" are all valid. The parse(CharSequence text) method uses DateTimeFormatter.ISO_LOCAL_TIME, which per https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#ISO_LOCAL_TIME accepts such variations.
475376 (18) [Avatar] Offline
#16
Page 285 section 4.6.3 LocalDateTime: delimiter between seconds and nanoseconds should be a decimal point, not a colon.
It stores a value like 2050-06-18T14:20:30:908765 (year-month-dayThours:minutes:seconds:nanoseconds).

should be
It stores a value like 2050-06-18T14:20:30.908765 (year-month-dayThours:minutes:seconds.nanoseconds).
475376 (18) [Avatar] Offline
#17
Page 293 Table 4.4: symbol in last line (for meaning "escape for text") should be a regular apostrophe ('), not a back quote (`).
475376 (18) [Avatar] Offline
#18
Page 295 mid-page states,
Also, using a pattern letter doesn't specify the count of digits or texts. For an example, using Y or YYYY to format a date object returns the same results.

That's misleading at best. Using YY or YYYYY may produce different results, as could using M vs. MM vs. MMM vs. MMMM, etc. As documented at https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#patterns, the count of pattern letters determines the format.

As an illustration,
LocalDate date = LocalDate.of(2057, 8, 11);
String[] patterns = {"Y M d", "YY MM d", "YYY MMM d", "YYYY MMMM d",
                    "YYYYY MMMMM d"};
for (String p : patterns)
    System.out.println(p + " -> " + DateTimeFormatter.ofPattern(p).format(date));

outputs (for en_US locale):

Y M d -> 2057 8 11
YY MM d -> 57 08 11
YYY MMM d -> 2057 Aug 11
YYYY MMMM d -> 2057 August 11
YYYYY MMMMM d -> 02057 A 11

whereas

DateTimeFormatter.ofPattern("Y M ddd");

throws

java.lang.IllegalArgumentException: Too many pattern letters: d
475376 (18) [Avatar] Offline
#19
Page 302 third bullet: /u0000 should read \u0000
475376 (18) [Avatar] Offline
#20
Page 302 third from last bullet:
Unlike arrays, you may not specify an initial size to create an ArrayList.

You most certainly may, using the ArrayList(int initialCapacity) constructor. And with arrays, the size specified is what it is -- it's not just an "initial" size.
475376 (18) [Avatar] Offline
#21
Page 308 5th bullet:
You can query whether any of three units of a Period is negative using the methods isNegative and isZero. A Period instance is negative if all three of its units are zero.

should instead read something like,
You can query whether any of three units of a Period is negative using the method isNegative, and whether all three of its units are zero using the method isZero.

475376 (18) [Avatar] Offline
#22
Page 333 line 3: else should be indented four spaces (aligning with the if (score <400) line on the previous page). Ironically, this error is in code following the text "Here's the code with the correct indentation:" but it's still (partially) incorrect.
475376 (18) [Avatar] Offline
#23
Pages 415-416 figures 6.15 through 6.17: All seven lines with
System.out println
should instead have
System.out.println
and in figure 6.15, abstact should read abstract.
475376 (18) [Avatar] Offline
#24
Page 416 Figure 6.16: In all three blocks, the line
Animal lion = new Animal();
should be changed to
Jumpable lion = new Animal();
This change should be instead of
In the rectangle that shows changing of an abstract method to a static method (row 2, column 2), class Animal shouldn't include definition of method maxDistance();
which was added to the errata per post #10.

Figure 6.16 is attempting to illustrate how modifying the interface by changing the abstract method to a default method allows the code to continue to compile, but changing it to a static method can result in compilation failure in calling code. The suggestion by user 428299 to remove the maxDistance() method from the Animal class in the row 2, column 2 code block does result in the marked compilation failure but otherwise doesn't really make sense for the example.

Note also that Figure 6.17 has Jumpable lion rather than Animal lion of Figure 6.16.

mala.gupta wrote:
428299 wrote:Hi,
In page 416, figure 6.16 "What happens when you change an abstract method in an interface to a default or static method", please, read my comment in line 14 of the code.

interface Jumpable {
static int maxDistance() {
return 200;
}
}
class Animal implements Jumpable {}
public int maxDistance() {
return 100;
}
}
class Forest {
public static void main(String args[]) {
Animal lion = new Animal();
System.out println(lion.maxDistance()); // ERROR: in the book says that this code "Doesn't compile", but it compiles because we still have the method maxDistance in Animal class.
}
}


The above code compiles. The below code won't compile, because we have removed the method maxDistance() in Animal class. This way:

interface Jumpable {
static int maxDistance() {
return 200;
}
}
class Animal implements Jumpable {}
//Removing this code because the method is static, then it is optional to have the method maxDistance here.
/*public int maxDistance() {
return 100;
}*/ 
}
class Forest {
public static void main(String args[]) {
Animal lion = new Animal();
System.out println(lion.maxDistance()); //Now, because we are refering tho "maxDistance" using the class Animal, the code "Doesn't compile".
}
}


I think the book wanted to explain the second option (showing a compilation error) and it forgot to remove the maxDistance from class Animal.

Please, correct me if I am wrong.

Thanks.



Hi there -

Thanks for reporting this issue.

You are correct. I've added it to the book's errata.

With much respect,
Mala
475376 (18) [Avatar] Offline
#25
Pages 452-453:
You can implement polymorphism by using either classes or interfaces. In the case of polymorphism with classes, the base class can be either an abstract class or a concrete class. The method in question here also need not be an abstract method. When you implement polymorphism using interfaces, you must use an abstract method from the interface.
What about polymorphism with default interface methods (described on pages 444-445)? That last sentence should perhaps instead read something like:
When you implement polymorphism using interfaces, you can use abstract or default methods from the interface.



315595 (1) [Avatar] Offline
#26
Chapter 3.6.2 "Read and write object fields" says
Using constructors to write values to object fields


A constructor can read values from object fields too. This can make sense when an object field was written within the initializer block.

This sample will print "10":
public class Test {

	int i, c;
	
	{
		i = 5;
	}
	
	Test(){
		c = 2*i; // Constructor reads i, which was written inside initializer block
	}
	
	public static void main(String[] args) {
		Test test = new Test();
		System.out.println(test.c);
	}
}

475376 (18) [Avatar] Offline
#27
Page 489 Table 7.1 in second column: File Closing Exception should be I/O Exception
475376 (18) [Avatar] Offline
#28
Pages 499 to 500, last sentence of section 7.4.10:
The simple reason for this rule is that RuntimeExceptions aren't checked exceptions, and they may not be caught or declared to be thrown by your code (exception categories are discussed in detail in section 7.2).
is incorrect as runtime exceptions may indeed be caught or declared, but don't have to be. Perhaps "may not" was intended to read "may or may not".
475376 (18) [Avatar] Offline
#29
Page 502 Twist in the Tale 7.3 (and answer on page 656):

I believe the correct answer, if there is one (VM-dependent?), is c, not b. As an experiment I tried running the code on two different VMs; on both the output matched answer c. And there is no such thing as java.lang.StackOverFlowError; in answer choices b and d that was perhaps meant to read java.lang.StackOverflowError.

Also, the last sentence of the answer explanation on page 656:
For example, error-handling code for StackOverFlowError may execute but (as the name suggests) may not execute for VirtualMachineError.
should perhaps read
For example, error-handling code for StackOverflowError may execute but (as the name suggests) may not execute for all VirtualMachineErrors.
because 1) it's StackOverflowError not StackOverFlowError and 2) StackOverflowError is a VirtualMachineError.
475376 (18) [Avatar] Offline
#30
Page 511 Figure 7.21: The text java.lang.AritmeticException should be java.lang.ArithmeticException
475376 (18) [Avatar] Offline
#31
Page 535 last paragraph of answer explanation of Q7-6:
Option (e) code will compile successfully. If a method declares to throw Exception, it might not actually throw it. This only applies to Exception (because RuntimeException subclasses it), runtime exceptions, and errors.
The last sentence is incorrect. A method can declare throwing any Throwable or subclass thereof (whether checked exception, runtime exception, or error) even if it doesn't actually throw anything.