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 )It will print 34 if lines 4 to 7 are replaced with:
About Question enthuware.ocpjp.v8.2.1901 :
Moderators: Site Manager, fjwalraven
-
- Posts: 32
- Joined: Tue Oct 06, 2015 9:06 am
- Contact:
About Question enthuware.ocpjp.v8.2.1901 :
The explanation of one of the answers contains the following:
-
- Site Admin
- Posts: 10078
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1901 :
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.
In the exam, you will need to pick the best option in case you spot an ambiguity.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 51
- Joined: Wed Sep 28, 2011 12:14 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1901 :
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
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
-
- Site Admin
- Posts: 10078
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1901 :
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.
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.
If you like our products and services, please help us by posting your review here.
-
- Posts: 4
- Joined: Tue Jul 25, 2017 12:05 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1901 :
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.
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.
-
- Site Admin
- Posts: 10078
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1901 :
Changed. But it is a wrong option anyway.
thank you for your feedback!
thank you for your feedback!
If you like our products and services, please help us by posting your review here.
-
- Posts: 29
- Joined: Sun Jul 16, 2017 4:24 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1901 :
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.
The filter method of an IntStream takes an IntPredicate; test1 and test2 are declared as Predicate<Integer>, not as IntPredicate.
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
-
- Site Admin
- Posts: 10078
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1901 :
Yes, that is another reason it will fail to compile. I have added this to the explanation.
thank you for your feedback!
thank you for your feedback!
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: No registered users and 11 guests