posted 11 months ago

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

Suppose

Please clarify if my understanding is not right.

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.

posted 9 months ago

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

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

posted 9 months ago

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

posted 9 months ago

oh..in book is chap 20...sorry, my mistake..

posted 9 months ago

- 1

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 .

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 .

[OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]

Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2