• 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

Sybex Practice Exam book - Chap 20 Q14

 
Ranch Hand
Posts: 50
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

A. (a,b) -> (a-b)
B. (a,b) -> 5
C. (a,b) -> i++
D. None of the above are appropriate.

The answer in the book is B, because it satisfies the two requirements - being associative and stateless. I totally agree with this answer if the reduce had just two arguments - identity and accumulator.
I am confused here , because there is a combiner also present in the reduce method which is s1+s2. Now, combiner has the contract that should return u, which is satisfied here as identity is 0. There is one more requirement : should be equivalent to
Suppose u and t both here are 5 as accumulator returns 5 for any two values in stream. so, combiner.apply(5, 5) is 10 whereas accumulator.apply(5,5) would return 5.  So, as a whole , to me the answer D looks closer.
Please clarify if my understanding is not right.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I'm also confused here
My explanation could be that in this case the combiner cannot be considered a function of two variables f(u, a(i,t)) because a(i,t) returns always a constant. Therefore we have more something like: f(x) = x+c, whereas c is a constant. And the compatibility requirement between function combiner and function accumulator is not more relevant because the second one is a constant.
Though, a little help in order to understand better the explanation would be appreciated.
Thanks
 
Zanna Bianca
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I doubled checked this question can be found in Sybex OCA OCP Practice Test Chapter 19, not Chap 20, Q14.
 
Zanna Bianca
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oh..in book is chap 20...sorry, my mistake..
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That sounds reasonable. I'm going to check with Scott. Parallel streams make my head spin.

Note that there is a difference in chapter # between the internet and book for the later half. The web counts the OCA practice exam as a chapter # and the book does not. So it could have easily been both ch 19 and 20 .
 
Straws are for suckers. Now suck on this tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic