Win a copy of Kotlin for Android App Development this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Errata for OCP: Oracle Certified Professional Java SE 8 Programmer II - Chapter 7  RSS feed

 
Ranch Hand
Posts: 238
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, the question says:

Assuming MyTask is an abstract class that implements the ForkJoinTask interface, what statements about the following code are true?



ForkJoinTask is not an interface, it's an abstract class: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ForkJoinTask.html

Even with this corrected, I'm still not sure about the code:



The fork().join() line does not compile because it cannot cast an Object to an int. It doesn't compile when changing FindMin to extend RecursiveTask either.

The third problem I had was with option C:

C. MyTask inherits RecursiveTask.



Not necessarily. It could extend ForkJoinTask and implement compute() and other methods in a similar way to RecursiveTask, but how can you know for sure that it extends RecursiveTask?

I would appreciate some clarification on these points - this is quite an involved topic, so it could well be me not getting it right.

Thank you.
 
author
Posts: 4099
21
Eclipse IDE Flex Google Web Toolkit
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It should say "extends the ForkJoinTask class", not inherits the interface. Errata noted.

The rest of the problem is fine as is. The idea is you have to know the difference between RecursiveTask and RecursiveAction to pick between B and C. Since the compute() method returns a value, C is the best choice candidate. You couldn't also have a compute() method that had a return type of void in a parent class, because this would violate rules for overriding, so B is not possible.

You assume the code does not compile but consider if MyTask includes a generic value in its inheritance structure. Can anyone construct a version of MyTask that would compile? Hint: it can be done in one line.

The rest is covered in the explanation in the solution guide.
 
author & internet detective
Posts: 39129
723
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Scott Selikoff wrote:It should say "extends the ForkJoinTask class", not inherits the interface. Errata noted.


And logged.

Also this is question 9 which I don't see mentioned anywhere in the thread.
 
T Vergilio
Ranch Hand
Posts: 238
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Scott,

Thank you very much for the answer.

I see what you mean by one of the parent classes in the inheritance structure having a generic type. Still, you could have this situation:



Where MyClass wouldn't need to inherit from RecursiveAction or RecursiveTask. The code would still compile and run.

Don't you agree?

Ps: Yes, Jeanne, it's question 9. Sorry, that's what exhaustion does to you
 
Scott Selikoff
author
Posts: 4099
21
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you might be overthinking this one a little... the code compiles with the following implementation of MyTask:



As far as skipping RecursiveAction/RecursiveTask, that doesn't really match the text. For the fork/join framework, we use one or the other. The book (and the exam) expects you to use one of these two classes.
 
T Vergilio
Ranch Hand
Posts: 238
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question 17 of the review questions, page 401.

The class doesn't import java.util.concurrent.atomic.*, so compilation will fail because of line w1 (the one where the AtomicInteger is declared), making option D correct.
 
Scott Selikoff
author
Posts: 4099
21
Eclipse IDE Flex Google Web Toolkit
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that the exam now uses the following disclaimer:

Assume the following:
Missing package and import statements: If sample code do not include package or import statements, and the question does not explicitly refer to these missing statements, then assume that all sample code is in the same package, and import statements exist to support them

 
T Vergilio
Ranch Hand
Posts: 238
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm... but the class does import java.util.concurrent.*

If it provides the full code, including one import statement, shouldn't we check to see that all the imports are there?
 
Scott Selikoff
author
Posts: 4099
21
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps for this question but on the exam this would be perfectly acceptable.
 
T Vergilio
Ranch Hand
Posts: 238
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On page 393, under "Be able to use the concurrent collection classes":

(...) such as ConcurrentHashMap and ConcurrentDeque.


There is no such thing as ConcurrentDeque. ConcurrentLinkedDeque, maybe?
 
Jeanne Boyarsky
author & internet detective
Posts: 39129
723
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

T Vergilio wrote:On page 393, under "Be able to use the concurrent collection classes":

(...) such as ConcurrentHashMap and ConcurrentDeque.


There is no such thing as ConcurrentDeque. ConcurrentLinkedDeque, maybe?


Confirmed and logged in errata.

I also noted your comment about the imports on our private list. Which it's not wrong per se (as one *could* insert the missing import up top), it certainly could be improved
 
T Vergilio
Ranch Hand
Posts: 238
5
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Jeanne Boyarsky wrote:one *could* insert the missing import up top



Indeed, that's a good argument. Luckily the exam isn't that mean!
 
Greenhorn
Posts: 16
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

In OCP book option D is mentioned as incorrect answer : The code produces a ForkJoinPool at runtime.

Could you please explain how it is possible not to produce ForkJoinPool instance if task is passed to invoke method of the same ForkJoinPool?



Thanks
 
Jeanne Boyarsky
author & internet detective
Posts: 39129
723
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John,
Thanks for asking. That answer choice was not the one we intended. The errata says:

#9: Choice D contains a typo and doesn't make sense as written. It should say "The code produces an infinite loop at runtime not the code produces a ForkJoinPool at runtime.



Scott actually noticed this problem after it was too late to get it fixed in the book.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Jeanne,

A bit of errata in errata.

The errata says:


Choice D contains a typo and doesn't make sense as written. It should say "The code produces an infinite loop at runtime not the code produces a ForkJoinPool at runtime.



Could I possibly suggest that you updated errata to have "Chapter 7 mock question" instead of current "Chapter 7" in Chapter column ? Some other errata records have it this way which makes it much easier to find information on the page.

Thanks!
 
Evan Certified
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please disregard my post above. I mixed up page numbers.
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!