Susan Harkins (212) [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