OCP Flashcards – 4. Lambda Built-in Functional Interfaces

OCP Exam Objective 4 – Lambda Built-in Functional Interfaces

Flashcard OCP.4.Lambda.Built-in.Functional.Interfaces.001

Which interface accepts an argument of the type long while producing a double value result?

Click here to view answer
LongToDoubleFunction

 

Flashcard OCP.4.Lambda.Built-in.Functional.Interfaces.002

Which package in the standard Java 8 library provides target types for lambda expressions and method references?

Click here to view answer
java.util.function

 

Flashcard OCP.4.Lambda.Built-in.Functional.Interfaces.003

How many operands does the UnaryOperator‘s functional method accept?

Click here to view answer
One

 

Flashcard OCP.4.Lambda.Built-in.Functional.Interfaces.004

What is the functional interface for an operation with two double operands that returns a double value?

Click here to view answer
DoubleBinaryOperator

 

Flashcard OCP.4.Lambda.Built-in.Functional.Interfaces.005

Is the following LOC is valid, and why?

BiFunction<IntUnaryOperator> myFunc = x -> y -> x / y;

Click here to view answer
No, it is not valid because BiFunction needs three arguments.

 

Flashcard OCP.4.Lambda.Built-in.Functional.Interfaces.006

How would you correct the LOC in the previous question?

Click here to view answer
For example:

BiFunction<Integer, Double, DoubleUnaryOperator> myFunc = (x, z) -> y -> x / z;

 

Flashcard OCP.4.Lambda.Built-in.Functional.Interfaces.007

Is the interface LongBinaryOperator generic, and why?

Click here to view answer
No, it is not because it’s already a primitive long-valued specialization

 

Flashcard OCP.4.Lambda.Built-in.Functional.Interfaces.008

What is the functional method in the IntFunction interface? Select one:

  • Integer apply(int value)
  • R apply(int value)
  • R applyAsInt(T value)
  • T applyAsInt(T value)
Click here to view answer
It’s R apply(int value) because the interface in question is defined as IntFunction<R>.

 

Flashcard OCP.4.Lambda.Built-in.Functional.Interfaces.009

What is the functional interface for an operation with two int operands that returns an int value?

Click here to view answer
IntBinaryOperator

 

Flashcard OCP.4.Lambda.Built-in.Functional.Interfaces.010

What is the functional interface for an operation with two operands of the same datatype?

Click here to view answer
BinaryOperator<T>

 

Flashcard OCP.4.Lambda.Built-in.Functional.Interfaces.011

What is more efficient when handling primitives: Predicate<Integer> or IntPredicate?

Click here to view answer
IntPredicate because Predicate<Integer> would first perform autoboxing.

 

Flashcard OCP.4.Lambda.Built-in.Functional.Interfaces.012

What are the int-valued primitive specializations of the standard functional interfaces?

Click here to view answer
  • IntConsumer
  • IntSupplier
  • IntPredicate
  • IntFunction
  • IntToLongFunction
  • IntToDoubleFunction
  • IntUnaryOperator
  • IntBinaryOperator
  • ObjIntConsumer
  • ToIntFunction
  • ToIntBiFunction

 

Flashcard OCP.4.Lambda.Built-in.Functional.Interfaces.013

True or false: all int-valued primitive specializations of the standard functional interfaces are not generic?

Click here to view answer
False because of IntFunction<R>, ObjIntConsumer<T>, ToIntFunction<T> and ToIntBiFunction<T, U>

 

Flashcard OCP.4.Lambda.Built-in.Functional.Interfaces.014

How Supplier differs from Consumer?

Click here to view answer
While Supplier accepts no arguments and returns a value, the Consumer interface takes one argument, returns nothing and, unlike most other functional interfaces, is expected to operate via side-effects.

 

Flashcard OCP.4.Lambda.Built-in.Functional.Interfaces.015

True or false: two among the following functional interfaces accept an argument of any type and return a double value?

DoubleFunction<R>, ObjDoubleConsumer<T>, ToDoubleFunction<T> and ToDoubleBiFunction<T, U>

Click here to view answer
False because only ToDoubleFunction<T> satisfied the stated conditions; besides, why would anyone build several interfaces to achieve the same result?

 

Flashcard OCP.4.Lambda.Built-in.Functional.Interfaces.016

What is the main advantage of primitive specializations of functional interfaces?

Click here to view answer
Improved performance by avoiding autoboxing operations

 

Flashcard OCP.4.Lambda.Built-in.Functional.Interfaces.017

In what way a UnaryOperator differs from a BinaryOperator?

Click here to view answer
A UnaryOperator accepts a single argument while BinaryOperator works on two arguments.

 

Flashcard OCP.4.Lambda.Built-in.Functional.Interfaces.018

What is the return type of a UnaryOperator functional interface?

Click here to view answer
Same as its operand’s type

 

Flashcard OCP.4.Lambda.Built-in.Functional.Interfaces.019

Which interface does UnaryOperator extend?

Click here to view answer
Function

 

Flashcard OCP.4.Lambda.Built-in.Functional.Interfaces.020

What is the functional interface for an operation with two long operands that returns a long value?

Click here to view answer
LongBinaryOperator

 

Flashcard OCP.4.Lambda.Built-in.Functional.Interfaces.021

What is the functional method’s signature in the IntConsumer interface?

Click here to view answer
void accept(int value)

 

Flashcard OCP.4.Lambda.Built-in.Functional.Interfaces.022

What is the functional method’s signature in the IntPredicate interface?

Click here to view answer
boolean test(int value)

 

Flashcard OCP.4.Lambda.Built-in.Functional.Interfaces.023

What is the functional method’s signature in the IntSupplier interface?

Click here to view answer
int getAsInt()

 

Flashcard OCP.4.Lambda.Built-in.Functional.Interfaces.024

What is the functional method’s signature in the IntFunction interface?

Click here to view answer
R apply(int value)

 

Flashcard OCP.4.Lambda.Built-in.Functional.Interfaces.025

What is the functional method’s signature in the IntToLongFunction interface?

Click here to view answer
long applyAsLong(int value)

 

Flashcard OCP.4.Lambda.Built-in.Functional.Interfaces.026

What is the functional method’s signature in the IntBinaryOperator interface?

Click here to view answer
int applyAsInt(int left, int right)

 

 

Leave Comment

Your email address will not be published.