• 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 OCP Appendix A Chapter 7 Question 8.

 
Greenhorn
Posts: 7
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have a doubt about a one sentence in an explanation.

The findAny() method will return the value from the first thread that retrieves a record. Therefore, the output is not guaranteed for either serial or parallel stream



I think findAny() on serial Stream will output first element as described in Chapter 7.

System.out.print(Arrays.asList(1,2,3,4,5,6).stream().findAny().get());
This code consistently outputs the first value in the serial stream, 1.



 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
According to the javadoc of the findAny() method, the behavior of this operation is explicitly nondeterministic; it is free to select any element in the stream.

So in a non-parallel operation, it will most likely return the first element in the Stream but there is no guarantee for this.
 
Jerzy Los
Greenhorn
Posts: 7
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I see that there was already a topic about that, but it wasn't added to the errata page.

https://coderanch.com/t/677243/certification/findAny-Enthuware-Boyarsky-Selikoff

Regards,
jml
 
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

Jerzy Los wrote:I see that there was already a topic about that, but it wasn't added to the errata page.

https://coderanch.com/t/677243/certification/findAny-Enthuware-Boyarsky-Selikoff


That's because I don't believe it is an errata. While I agree that a serial stream does return the first element on findAny(), I don't think it is guaranteed by the specification.
 
Jerzy Los
Greenhorn
Posts: 7
3
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So maybe errata to a flash card ;)

Q: The findAny() method always returns the first result in the stream.
A: On serial streams it returns the first element, but on parallel streams it can return any element of the stream.


Some other suggestions:
Mock exam question with assert x >= 1 && x <= 6;
Explanation: Since no AssertionError is thrown, the code outputs 7, so D is true and E is false. Therefore, the answer is D and E.

Flash Card with lambda requires parentheses on the left side when two or more arguments
Answer: "It also requires parentheses  when there are zero arguments" is incomplete, it also requires when is one but with a type.

Mock exam there is line f2 two times:
for(Integer item : list2) list2.add(item); // f2
for(Integer key : map3.keySet()) map3.remove(key); // f2

Mock exam question about OutputStream class parto of explanation:
All streams, including instances of OutputStream, should be closed after use, so E is correct. Finally, an OutputStream may be periodically flushed, but it is not required for use, so F is incorrect.
i believe it should be:
All streams, including instances of OutputStream, should be closed after use, so F is correct. Finally, an OutputStream may be periodically flushed, but it is not required for use, so G is incorrect.

Mock exam a question with  z.accept(1.0); z variable is undeclared so code will not compile, but it's mentioned in an explanation: Line 8 calls accept(), making it a consumer.

Regards,
jml
p.s. i have passed OCP today, so there will be no more suggestions from my side ;) Thanks for a great book.

 
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
Jim,
Congrats on passing the exam!

Jerzy Los wrote:Mock exam question with assert x >= 1 && x <= 6;
Explanation: Since no AssertionError is thrown, the code outputs 7, so D is true and E is false. Therefore, the answer is D and E.


Agreed. Added to the errata. Luckily it is just a typo in the explanation and the actual answer is correct in the engine!

Jerzy Los wrote:Mock exam there is line f2 two times:
for(Integer item : list2) list2.add(item); // f2
for(Integer key : map3.keySet()) map3.remove(key); // f2


Agreed. Added to the errata.

Jerzy Los wrote:Mock exam question about OutputStream class parto of explanation:
All streams, including instances of OutputStream, should be closed after use, so E is correct. Finally, an OutputStream may be periodically flushed, but it is not required for use, so F is incorrect.
i believe it should be:
All streams, including instances of OutputStream, should be closed after use, so F is correct. Finally, an OutputStream may be periodically flushed, but it is not required for use, so G is incorrect.


Agreed. Added to the errata.

Jerzy Los wrote:Mock exam a question with  z.accept(1.0); z variable is undeclared so code will not compile, but it's mentioned in an explanation: Line 8 calls accept(), making it a consumer.


Agreed. Added to the errata.
 
reply
    Bookmark Topic Watch Topic
  • New Topic