• Post Reply Bookmark Topic Watch Topic
  • New Topic

Sybex Practice Exam book - Chap 20 Q14  RSS feed

 
Ranch Hand
Posts: 50
3
  • Mark post as helpful
  • send pies
  • 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: 8
  • Mark post as helpful
  • send pies
  • 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: 8
  • Mark post as helpful
  • send pies
  • 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: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh..in book is chap 20...sorry, my mistake..
 
author & internet detective
Sheriff
Posts: 37820
582
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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 .
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!