Page 1 of 1

About Question enthuware.ocpjp.v8.2.1901 :

Posted: Mon Oct 12, 2015 6:01 am
by Martyjee
The explanation of one of the answers contains the following:
It will print 34 if lines 4 to 7 are replaced with:
I know that it will always print the values that evaluate to 'false' first because that explicit iteration order has been hardcoded into Java (I decompiled the Java bytecode). But in general it is dangerous to assume this ordering and to assume that the takers of this test will not complain! (guilty ;))

Re: About Question enthuware.ocpjp.v8.2.1901 :

Posted: Mon Oct 12, 2015 10:57 pm
by admin
I agree that the order is not 100% guaranteed in this case but that can be a cause of complaint only if the question had another option that says it will print 43, or "None of the above". In absence of such options, this is the best option.

In the exam, you will need to pick the best option in case you spot an ambiguity.

HTH,
Paul.

Re: About Question enthuware.ocpjp.v8.2.1901 :

Posted: Sat Oct 29, 2016 3:22 am
by Ciprian Mihalache
My problem with this question (and not only with this question) is its section/topic.
I am trying to learn progressive, by following the Oracle topics, then, once I learned a topic I try to respond to your questions that are related to that topic.
This question is set to topic "03 - Java Collections and Streams with Lambdas", however, one should know the "04 - Collection Operations with Lambda" topic (Perform calculations by using Java Stream methods, such as count(), max(), min(), average(), and sum() + Develop code that uses the Stream.collect() method and Collectors class methods, such as averagingDouble(), groupingBy(), joining(), and partitioningBy()) and also "06 - Lambda Cookbook" topic (Develop code that creates a stream by using the Arrays.stream() and IntStream.range() methods) in order to properly answer it.
Logically, it should be in the highest topic it touches, which is "06 - Lambda Cookbook" in this case
Thank you

Re: About Question enthuware.ocpjp.v8.2.1901 :

Posted: Tue Nov 01, 2016 10:17 pm
by admin
By highest, you mean numerically i.e. 6>4, 3 ?
If a question touches multiple objectives, it is a bit subjective to decide which objective should it be categorized into. I am not sure if there can be one rule that can fit all situations. So we leave it to the author on his/her discretion.
We can change it if it is completely absurd, of course.
-Paul.

Re: About Question enthuware.ocpjp.v8.2.1901 :

Posted: Fri Oct 20, 2017 10:20 am
by alexm1980
You need to change this line of code from the answers:

long count2 = primeStream().reset().filter(test2).count(); //6

with

long count2 = primeStream.reset().filter(test2).count(); //6

because primeStream is a Stream and not a method.

Re: About Question enthuware.ocpjp.v8.2.1901 :

Posted: Sat Oct 21, 2017 11:54 am
by admin
Changed. But it is a wrong option anyway.
thank you for your feedback!

Re: About Question enthuware.ocpjp.v8.2.1901 :

Posted: Sun Nov 04, 2018 12:30 pm
by philippe
I think there is another problem with the third answer next to the fact that the of() method of IntStream only takes an int or varargs parameter of type int.

Code: Select all

It will print 4 3 if line //4 and //6 are replaced with: 
long count1 = IntStream.of(primes).filter(test1).count();//4 
and 
long count2 = IntStream.of(primes).filter(test2).count();//6
The filter method of an IntStream takes an IntPredicate; test1 and test2 are declared as Predicate<Integer>, not as IntPredicate.

Re: About Question enthuware.ocpjp.v8.2.1901 :

Posted: Sun Nov 04, 2018 9:12 pm
by admin
Yes, that is another reason it will fail to compile. I have added this to the explanation.
thank you for your feedback!