• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Errata for OCP: Oracle Certified Professional Java SE 8 Programmer II Study Guide - page 369

 
Greenhorn
Posts: 4
1
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I found an issue in Chapter 7, page 369 when I decided to try out the code listed there.



Expected result: The program should take roughly 40 seconds to complete due to the Thread.sleep(10) with 4000 records.

Actual result: The program completes right away no matter what huge value you put in Thread.sleep() because the intermediate operations that call that method are not running.

After some head scratching, I tried replacing the count() method with different terminal operations, like forEach, and only then did I get the expected result.  After looking at the API for the count() method I found the following:

An implementation may choose to not execute the stream pipeline (either sequentially or in parallel) if it is capable of computing the count directly from the stream source.  In such cases no source elements will be traversed and no intermediate operations will be evaluated.



In this situation, there is no need to call the intermediate operations, so it doesn’t, and we don't get to see the effect of the Thread.sleep() method.  So, the count() method should be replaced by some other terminal operation so that the intermediate operations run to call the processRecord() method with Thread.sleep().
 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please look here [edit]this is the correct link (sorry for my mistake)
[/edit] and check whether I have linked to the correct book. I can't find anything for page 369, so this looks like something new.
 
Bartender
Posts: 5465
212
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Dave,

I'm not sure about this. It is true what you write, and I see the effect when I run the code. I did not know this. But if I look at the Java 8 documentation I am unable to find any of this documented (I do see it in the Java 10 API). So, it is probably something that was built into Java 9+. I have deleted my java 8, so can't test, but have a cow for your interesting remark.
 
Campbell Ritchie
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You deserve the cow, Piet, for noticing the different behaviour in different versions; I installed Java8u202 and it took slightly over 40″ to run.

$ java -version
java version "1.8.0_202"
Java(TM) SE Runtime Environment (build 1.8.0_202-b08)
Java HotSpot(TM) 64-Bit Server VM (build 25.202-b08, mixed mode)
$ javac -version
javac 1.8.0_202
...
java WhaleDataCalculator

Tasks completed in: 40.864 seconds


 
Dave Martino
Greenhorn
Posts: 4
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah, yes, it looks like that was something added after Java 8, so technically not errata at the time it was published.  With the authors working on the OCA/OCP 11 versions now, however, I think it's probably still something that would need to be changed for the new edition.  

Thanks for the cow!  
 
Campbell Ritchie
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Agree, but if the exam is geared to Java8, the original version is, as you say, correct for Java8.

Interesting question
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dave: It probably won't surprise you that we tested with Java 8 .

Dave/Piet: I added that to our to do list for the Java 11 book. Thanks for pointing it out. Knowing about it up front will make things faster for us.
 
Rancher
Posts: 261
12
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I have a question related to the aforementioned book also in Chapter 7 Concurrency (but on page 337).

As you can see in the image, the following is stated: "... the ExecutorSercive interface does not implement AutoCloseable...". Since both are interfaces and one interface does not implement another interface - but rather extends - shouldn't this be changed?

It is not (yet) mentioned on the errata list for the book.
Screenshot-2019-08-21-at-10.52.53.png
[Thumbnail for Screenshot-2019-08-21-at-10.52.53.png]
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Brecht Geeraerts wrote:Hi all,

I have a question related to the aforementioned book also in Chapter 7 Concurrency (but on page 337).

As you can see in the image, the following is stated: "... the ExecutorSercive interface does not implement AutoCloseable...". Since both are interfaces and one interface does not implement another interface - but rather extends - shouldn't this be changed?

It is not (yet) mentioned on the errata list for the book.


Good catch! I've added it to the errata list and credited you. We will be sure to fix this in our 1Z0-816 book!
 
Brecht Geeraerts
Rancher
Posts: 261
12
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Jeanny: Thanks and you are welcome.
 
reply
    Bookmark Topic Watch Topic
  • New Topic