About Question enthuware.ocpjp.v8.2.1856 :

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

Moderator: admin

Post Reply
surzhin
Posts: 7
Joined: Fri Dec 11, 2015 6:50 am
Contact:

About Question enthuware.ocpjp.v8.2.1856 :

Post by surzhin »

As per https://docs.oracle.com/javase/tutorial ... s/streams/:

A pipeline contains the following components:
A source: This could be a collection, an array, a generator function, or an I/O channel. In this example, the source is the collection roster.
Zero or more intermediate operations: An intermediate operation, such as filter, produces a new stream.
A terminal operation.

1. a source
2. an intermediate operation
3. a terminal operation
4. a reduction operation
5. a method reference
6. a lambda expression

You had to select 2 options. Why only two options?
So , 1 and 3. But why the operation number 2 is wrong?

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

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

Post by admin »

The statement that you've quoted says, "zero or more intermediate operations". That means an intermediate operation is not a must for a pipeline. That is why option 2 is incorrect.

HTH,
Paul.

ramy6_1
Posts: 124
Joined: Wed Feb 12, 2014 2:44 am
Contact:

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

Post by ramy6_1 »

Hello,

If an intermediate operation is optional , how we can use a pipeline ?

Can you provide a sample case using stream and terminal operation only ?

ramy6_1
Posts: 124
Joined: Wed Feb 12, 2014 2:44 am
Contact:

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

Post by ramy6_1 »

Hello ,

Appreciate your update.

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

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

Post by admin »

Not sure I understand your question. Taking the example from the link mentioned above:
roster.stream().forEach(e -> System.out.println(e.getName()));
is a valid pipeline without any intermediate operation.



-Paul.

vleunti
Posts: 4
Joined: Tue Aug 25, 2020 3:50 am
Contact:

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

Post by vleunti »

But this is also valid

roster.stream().filter(x->x.isEmpty());

source and intermediate operation, here we have no terminal operation. So, terminal operation is not a must, isn't ?

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

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

Post by admin »

It is valid as in valid code but will not do anything. Unless you have a terminal operation, nothing will be executed. So, it is not valid from the pipeline perspective.

Deleted User 6318

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

Post by Deleted User 6318 »

What would be the generator function source?

Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests