About Question enthuware.ocpjp.v8.2.1901 :

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
Martyjee
Posts: 32
Joined: Tue Oct 06, 2015 9:06 am
Contact:

About Question enthuware.ocpjp.v8.2.1901 :

Post 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 ;))

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

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

Post 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.
If you like our products and services, please help us by posting your review here.

Ciprian Mihalache
Posts: 51
Joined: Wed Sep 28, 2011 12:14 pm
Contact:

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

Post 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

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

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

Post 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.
If you like our products and services, please help us by posting your review here.

alexm1980
Posts: 4
Joined: Tue Jul 25, 2017 12:05 pm
Contact:

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

Post 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.

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

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

Post by admin »

Changed. But it is a wrong option anyway.
thank you for your feedback!
If you like our products and services, please help us by posting your review here.

philippe
Posts: 29
Joined: Sun Jul 16, 2017 4:24 pm
Contact:

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

Post 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.

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

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

Post by admin »

Yes, that is another reason it will fail to compile. I have added this to the explanation.
thank you for your feedback!
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 37 guests