Need some help with these, i have guessed at some but wanna make sure my answers
ID: 3731630 • Letter: N
Question
Need some help with these, i have guessed at some but wanna make sure my answers are right. Thank you
Terminal Stream operation ________ performs processing on every element in a stream (e.g., display each element).
forNext
for
forAll
forEach
QUESTION 2
Prior to Java SE 8, Java supported three programming paradigms. Java SE 8 adds ________.
procedural programming
object-oriented programming
generic programming
functional programming.
QUESTION 3
A nice performance feature of lazy evaluation is the ability to perform________ evaluation, that is, to stop processing the stream pipeline as soon as the desired result is available.
premature
short circuit
terminal
intermediate
QUESTION 4
What is the meaning of ( ) in the following lambda?
() -> System.out.println("Welcome to lambdas!")
the lambdas parameters are inferred
the lambdas parameters are supplied by a method reference
the lambda has an empty parameter list
the given expression is not a valid lambda
QUESTION 5
The basic generic functional interface ________ in package java.util.function contains method apply that takes a T argument and returns a value of type R. Calls a method on the T argument and returns that method’s result.
Consumer<T>
Function<T,R>
Supplier<T>
BinaryOperator<T>
QUESTION 6
________ is an intermediate operation that transforms a stream’s elements to new values and produces a stream containing the resulting (possibly different type) elements.
Transforming
Converting
Mapping
Translating
QUESTION 7
Class Arrays provides ________ stream methods for creating IntStreams, LongStreams and DoubleStreams from int, long and double arrays or from ranges of elements in the arrays.
virtual
package
overridden
overloaded
QUESTION 8
Collectors static method groupingBy with two arguments receives a Function that classifies the objects in the stream and another Collector (known as the ________ Collector).
stream
downstream
grouping stream
upsteam
QUESTION 9
Interface Stream (package java.util.stream) is a generic interface for performing stream operations on objects. The types of objects that are processed are determined by the Stream’s ________.
root
origin
source
start
QUESTION 10
A lambda expression represents a(n) ________ method—a shorthand notation for implementing a functional interface.
functional
unnamed
undesignated
anonymous
QUESTION 11
Method reduce’s first argument is formally called a(n) ________ value—a value that, when combined with any stream element using the IntBinaryOperator produces that element’s original value.
original
identity
preserve
self
QUESTION 12
Class IntStream provides terminal operations for common stream ________ count returns the number of elements, min returns the smallest int, max returns the largest int, sum returns the sum of all the ints and average returns an OptionalDouble (package java.util) containing the average of the ints as a value of type double.
consolidations
deductions
reductions
trims
QUESTION 13
The basic generic functional interface ________ in package java.util.function contains method test that takes a T argument and returns a boolean. Tests whether the T argument satisfies a condition.
Consumer<T>
Function<T,R>
Supplier<T>
Predicate<T>
QUESTION 14
Stream method ________ maps objects to double values and returns a DoubleStream. The method receives an object that implements the functional interface ToDoubleFunction (package java.util.function).
doubleMap
toDouble
mapToDouble
toDoubleStream
QUESTION 15
Collectors static method groupingBy with one argument receives a Function that classifies objects in the stream—the values returned by this function are used as the keys in a Map. The corresponding values, by default, are ________ containing the stream elements in a given category.
Lists
Arrays
Strings
Collectors
QUESTION 16
Functional interface BiConsumer’s accept method has two parameters. For Maps, the first represents the ________ and the second the corresponding ________.
key, variable
lambda, value
lambda, variable
key, value
QUESTION 17
Class Array’s ________ method is used to create a Stream from an array of objects.
stream
arrayToStream
createStream
objectToStream
QUESTION 18
An ________ (package java.util.stream) is a specialized stream for manipulating int values.
StreamOfInt
IStream.
IntegerStream
IntStream
QUESTION 19
The basic generic functional interface ________ in package java.util.function contains method get that takes no arguments and produces a value of type T. Often used to create a collection object in which a stream operation’s results are placed.
Consumer<T>
Function<T,R>
Supplier<T>
BinaryOperator<T>
QUESTION 20
The basic generic functional interface ________ in package java.util.function contains method accept that takes a T argument and returns void. Performs a task with its T argument, such as outputting the object, invoking a method of the object, etc.
Consumer<T>
Function<T,R>
Supplier<T>
BinaryOperator<T>
QUESTION 21
The basic generic functional interface ________ in package java.util.function contains method apply that takes two T arguments, performs an operation on them (such as a calculation) and returns a value of type T.
Consumer<T>
Function<T,R>
Supplier<T>
BinaryOperator<T>
QUESTION 22
By default, method sorted uses ________.
ascending order
the natural order for the stream's element type
descending order
the order specified in a command-line argument
QUESTION 23
Map method entrySet returns a Set of Map.Entry objects containing the Map’s ________.
values
keys
index
key–value pairs
QUESTION 24
The new language and library capabilities that support functional programming were added to Java as part of Project ________.
Utilitarian
Upsilon
Lambda
Utility
QUESTION 25
Functional interface Comparator’s default method ________ reverses an existing Comparator’s ordering.
invert
descending
reversed
downward
QUESTION 26
Map method ________ performs an operation on each key–value pair.
for
forNext
forEach
forAll
QUESTION 27
Stream mutable reduction operation ________ creates a new collection of elements containing the results of the stream’s prior operations.
combine
accumulate
gather
collect
QUESTION 28
________ is a method reference for an instance method that should be called on a specific object. It creates a one-parameter lambda that invokes the instance method on the specified object—passing the lambda’s argument to the instance method—and returns the method’s result.
Math::sqrt
System.out::println
TreeMap::new
String::toUpperCase
QUESTION 29
Stream method ________ eliminates duplicate objects in a stream.
distinct
discrete
unique
different
QUESTION 30
Intermediate Stream operation ________ results in a stream in which each element of the original stream is mapped to a new value (possibly of a different type)—e.g., mapping numeric values to the squares of the numeric values. The new stream has the same number of elements as the original stream.
mapped
map
mapper
mapping
QUESTION 31
Collectors static method ________ returns a Collector that counts the number of objects in a given classification, rather than collecting them into a List.
counter
count
counting
enumerate
QUESTION 32
Stream mutable reduction operation ________creates an array containing the results of the stream’s prior operations.
array
createArray
toArray
reduceArray
QUESTION 33
The intermediate Stream operation ________ results in a stream containing only the unique elements.
distinct
map
filter
limit
QUESTION 34
________ is a method reference for an instance method of a class. It creates a one-parameter lambda that invokes the instance method on the lambda’s argument and returns the method’s result.
Math::sqrt
System.out::println
TreeMap::new
String::toUpperCase
QUESTION 35
________ is a constructor reference. It creates a lambda that invokes the no-argument constructor of the specified class to create and initialize a new object of that class.
Math::sqrt
System.out::println
TreeMap::new
String::toUpperCase
QUESTION 36
You can define your own reductions for an IntStream by calling its ________ method. The first argument is a value that helps you begin the reduction operation and the second argument is an object that implements the IntBinaryOperator functional interface.
reduction.
lessen
trim
reduce
QUESTION 37
You can declare that an interface is a functional interface by preceding it with the @FunctionalInterface annotation. The compiler will then ensure that the interface contains ________; otherwise, it’ll generate a compilation error.
no abstract methods
all abstract methods
only one abstract method
one or more abstract methods.
QUESTION 38
The basic generic functional interface ________ in package java.util.function contains method get that takes no arguments and returns a value of type T.
UnaryOperator<T>
Function<T,R>
Supplier<T>
BinaryOperator<T>
QUESTION 39
Intermediate Stream operation ________ results in a stream with the specified number of elements from the beginning of the original stream.
distinct
map
filter
limit
QUESTION 40
IntStream method ________performs the count, min, max, sum and average operations in one pass of an IntStream’s elements and returns the results as an IntSummaryStatistics object (package java.util).
allStatistics.
completeStatistics.
entireStatistics.
summaryStatistics
forNext
for
forAll
forEach
Explanation / Answer
QUESTION 1) Terminal Stream operation ________ performs processing on every element in a stream (e.g., display each element).
ANS. forEach()
QUESTION 2) Prior to Java SE 8, Java supported three programming paradigms. Java SE 8 adds ________
ANS - Prior to Java SE 8, Java supported three programming paradigms—procedural programming, object-oriented programming and generic programming. Java SE 8 adds functional programming. So the Answer is "Functional Programming".
QUESTION 3) A nice performance feature of lazy evaluation is the ability to perform________ evaluation, that is, to stop processing the stream pipeline as soon as the desired result is available.
ANS - Terminal
QUESTION 4) What is the meaning of ( ) in the following lambda?
() -> System.out.println("Welcome to lambdas!")
ANS- The lambda has an empty list of parameters.
QUESTION 5) The basic generic functional interface ________ in package java.util.function contains method apply that takes a T argument and returns a value of type R. Calls a method on the T argument and returns that method’s result.
ANS - Function<T,R>
QUESTION 6) ________ is an intermediate operation that transforms a stream’s elements to new values and produces a stream containing the resulting (possibly different type) elements.
ANS- Mapping
QUESTION 7) Class Arrays provides ________ stream methods for creating IntStreams, LongStreams and DoubleStreams from int, long and double arrays or from ranges of elements in the arrays.
Ans - overloaded
QUESTION 8) Collectors static method groupingBy with two arguments receives a Function that classifies the objects in the stream and another Collector (known as the ________ Collector).
ANS - downstream
Please let me know in case of any clarifications required. Thanks!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.