About Question enthuware.ocpjp.ii.v11.2.1901 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
mario236
Posts: 3
Joined: Sun Nov 15, 2020 6:59 am
Contact:

About Question enthuware.ocpjp.ii.v11.2.1901 :

Post by mario236 »

Hi. Question from mocks for 1z0-817.

Given:
List<Integer> primes = Arrays.asList(2, 3, 5, 7, 11, 13, 17); //1
Stream<Integer> primeStream = primes.stream(); //2
Predicate<Integer> test1 = k->k<10; //3
long count1 = primeStream.filter(test1).count(); //4
Predicate<Integer> test2 = k->k>10; //5
long count2 = primeStream.filter(test2).count(); //6
System.out.println(count1+" "+count2); //7 Identify correct statements.


And the answer marked as the correct one is:

It will print 34 if lines 4 to 7 are replaced with: primeStream.collect(Collectors.partitioningBy(test1, Collectors.counting()))       .values().forEach(System.out::print);

The problem in this question is attempt to reuse already terminated Stream but the correct answer seems to be doing the same. Collect is a terminal operation too.

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.ii.v11.2.1901 :

Post by admin »

Yes, collect is a termination operation and you can't use that stream anymore. But, in this case, the call to collect returns a Map (because are passing Collectors.partitioningBy ), and you can call the values() method on a Map.
So, the correct answer is not really invoking another operation on a terminated stream.
If you like our products and services, please help us by posting your review here.

mario236
Posts: 3
Joined: Sun Nov 15, 2020 6:59 am
Contact:

Re: About Question enthuware.ocpjp.ii.v11.2.1901 :

Post by mario236 »

I replaced lines 4 & 7 but the intention was to replace lines from 4 to 7. Ok my mistake.

floryan
Posts: 17
Joined: Sun Sep 23, 2018 4:10 am
Contact:

Re: About Question enthuware.ocpjp.ii.v11.2.1901 :

Post by floryan »


It will print 34 if lines 4 to 7 are replaced with: primeStream.collect(Collectors.partitioningBy(test1, Collectors.counting()))       .values().forEach(System.out::print);
Couldn't it also be 43? Is the order of "values()" guaranteed?

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.ii.v11.2.1901 :

Post by admin »

Yes, it could be 43 also but that is not one of the options (neither is "None of the above") and since the best option needs to be picked, this is the right option.
If you like our products and services, please help us by posting your review here.

floryan
Posts: 17
Joined: Sun Sep 23, 2018 4:10 am
Contact:

Re: About Question enthuware.ocpjp.ii.v11.2.1901 :

Post by floryan »

admin wrote:
Mon Aug 30, 2021 9:22 pm
Yes, it could be 43 also but that is not one of the options (neither is "None of the above") and since the best option needs to be picked, this is the right option.
To me this is not correct. It says to identify correct statements and not "the one closest to being correct". The answer "It will print 34" COULD be correct. I feel the answer should be "It could print 34" or "It will either print 34 or 43".

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.ii.v11.2.1901 :

Post by admin »

You are technically correct that 34 or 43, would be more precise. However, in absence of any other option, we believe this option is correct because it does actually print 34.

Regarding, "It says to identify correct statements and not "the one closest to being correct"": Again, if there were an option that said "None of the above", then I would pick that option. But that is not the case.

In the real exam also, you may find options that may have some ambiguity and you would have to select the best option. The best option is the correct option for securing points for that question. So, I would suggest you to focus on what the question is trying to get at instead of trying to find absolute precision in statement.
If you like our products and services, please help us by posting your review here.

floryan
Posts: 17
Joined: Sun Sep 23, 2018 4:10 am
Contact:

Re: About Question enthuware.ocpjp.ii.v11.2.1901 :

Post by floryan »

I understand your point, I just think it's weird. For some questions we need to be absolute precise and every single word needs to be considered and evalutated. And then apparently there are other questions which have a rather vague wording and answers. I feel that there should be a consistent "style" across all questions.
This is not a criticism towards you but towards the creators of the exam, if their questions are indeed like that. Obviously we/I simply have to accept it the way it is.

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.ii.v11.2.1901 :

Post by admin »

I agree but there is a pattern that they follow. Here is what we have observed:

When they are looking for precision, they provide multiple similar options. For example, in this case, had they been looking for order, they would have given two options 34, 43, and 34 or 43, in which case you would pic 34 or 43. You may even see a "None of the above" in such questions.

Otherwise, when the focus of the question is something else, the options do not go into the finer details. For example, for a question such as "what will the following code print" and options, "compiler error, some output, exception at runtime", assuming the code causes an exception, they are not focusing on whether there is a NPE or FileNotFoundException. Just "exception" and so you will need to pick that.

Finally, we always say that the question and options are created by humans. So, you cannot avoid a little bit of ambiguity here and there. So, I would say, use your judgement and pick the best option as per the situation.

All the best!
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 65 guests