Font size
WorksheetsFinal
Total questions: 98
Worksheet time: 3hrs 16mins
What is a best practice for unit testing when lambdas are involved?
Replace a lambda that needs to be tested with a method reference
Test an auxiliary method
1 & 2
None of the above
Which one of the following stream operations is NOT stateless operation?
map
filter
sorted
limit
Which function to Transform Each Element of a Stream?
filter
map
reduce
collect
Lambda expressions are used primarily to define inline implementation of a functional interface
True
False
What can help us in avoiding NullPointeExceptions and null checks in java 8?
Optional
Required
NotNull
NotRequired
Predicate is in which package in Java 8?
java.util.predicate
java.util.object
java.util.objects
java.util.predict
What is an implementation of a functional interface called?
Lambda expression
Functor
Comparator
Implementation
What is stream in java 8?
Stream represents a sequence of objects from a source ,which supports aggregate operations
Stream can be used only to model object oriented systems
Stream represent associations represent methods
All of the above
What is the difference between Streams and Collections?
Stream operations do iteration internally and Collections operations to iteration explicitly
Stream operations do iteration explicitly and Collections operations to iteration internally
Stream operations do iteration internally and external and Collections operations to iteration only explicitly
None of the above
A method used to eliminate elements based on criteria
stream
filter
map
reduce
What is optional in java 8?
Optional object is used to represents boolean with absent value
Optional object is to used represent only integer with absent value
Optional is a container object which represents not- null objects
Optional object is used to represent only Strings with absent value
A method used to combine the result of prosessing on the elements of stream
stream
filter
flatMap
Collectors
Which of the following is the purpose of limit method in Java?
to concat the stream
to reduce the limit of stream
to sum up the stream
All of the above
What is the purpose of Predicate<T> Functional Interface?
It represents a super Type
It represents the subtype
It represents a predicate (Boolean -valued - function) of two argument
It represents a predicate (Boolean -valued - function) of one argument
Which one is true about Streams?
Do not store elements they operate on
Do not mutate their source
Stream operations are lazy when ever possible
All of the above
Which of the following operation can concatenate two streams?
Concat.stream(Stream,Stream)
Stream.concat(Stream,Stream)
Stream.concat(Stream)
Stream.concat()
Which of the following operation combine the terms of a stream into a single value by repeatedly applying an operation?
Reduce
Collector
Filter
All of the above
Which of the following best describes @FunctionalInterface?
Has two method
Has only one method
Has no method
All of the above
Which of the following operation is true about stream.skip(n) ?
Discards the first n elements
Discards the last n elements
Discards half of n elements
None of the above
Which of the following is true about singleton implementation?
It is thread safe
It is not thread safe
Sometimes It is thread safe
None of the above
Which of the following are benefits of Functional style programming?
Programs are compact and easy to read
Programs are thread safe
Easier to test
All of the above
What is the Free variable?
Variables that are passed as arguments in the lambda expression
Variables that are not parameters and not defined inside the block of code
It's not related to funcional programming concepts
None of the above
Which of the following can be a side effect for pure function?
Variable assignment
Making an http call
For loops
All of the above
The newly introduced Streams API is available in which package of Java 8?
java.io.streams
java.io.stream
java.util.streams
java.util.stream
Lambda expressions in java 8 are based on _________
Procedural programming
Functional programming
Data programming
All of the above
Stream operations in java 8 can be divided into __________
Terminal types
Intermediate types
All of the above
None of the above
In java 8 R apply(T t) is a method of ________
Function
Process
Predicate
None of the above
Which of the following is not terminal operation?
filter
count
collect(Collectors.to list())
None of the above
What is the Optional object used for?
Optional is used for optional runtime argument
Optional is used for optional spring profile
Optional is used to represent null with absent value
Optional means its not mandatory for method to return object
Which of the following is the most useful while working with parallel streams?
findAny
findFirst
distinct
None of the above
A TriFunction _________
takes one argument and returns two
takes two arguments and returns one
takes three arguments and returns one
takes two arrguments and returns two
Which is not true for a pure function?
It has same output for same input everytime
It does not have any side effects
It is not necessarily defined for every input
Many inputs can have same output
The higher order function in a stream filter should always return ___________
boolean
same instance as instance of argument
anything
long
Which is the correct way to execute a functional interface?
func.bind
func.call
func.apply
func
A piece of code to carry state from a defining context to an execution context is called a __________
lambda
closure
Anonymous function
pure function
What is the correct way to handle exceptions in a stream execution?
Handle it globally in the main method
Handle the appropriate exception inside the higher order function block and then raisea runtimeexception
Adjust your code to not throw exceptions at all
We do not need to handle exceptions in streams
Button::new can be resolved by the following lambda expression str -> new Button(str)
True
False
map() is one of the terminal operation operations
True
False
filter() is an intermideate operation used to
extract subtypes which satisfy a certain condition
change datatype
concat two strings
None of the above
filter() returns ___________
Only int values
Only String values
it is void
another stream
count() is a user defined or implemented method
True
False
Which one is true about functional programming?
we get the same output for any input
it is pure OOP
it is inheritance
None of the above
we can stream with in stream
True
False
Benefit of generics can be attributed to _________
Stronger type checks at compile time
Reduce downcasting
Supports the most general possible API for methods
All of the above
In the terminology and naming convention of Generics it is found List<T> where?
T is an element from the Java Collections Framework
T is a type
T is a key
T is a value
Advantages of functional programing rely on?
Purely functional -so threadsafe
Makes no commitments to an interaction path -so more parallelizable
Declaratice style -what and not how
All of the above
Facts about Streams in functional programming can be considered as?
Streams do no store elements they operate on
Streams do not mutate their source
Java implementation involve a combination of technical operations
All of the above
Collecting results is considered in a Stream?
An intermediate operation
A terminal operation
A stateful intermediate operation
A creating operation
How many INPUT arguments does the functional interface TriFunction<S T R U> accept?
Three input and produces one output
Two input and produces two output
One input and produces three output
Four input and produces zero output
Are local and anonymous inner classes allowed to?
Access to Instance variables of the enclosing class
Not access to Instance variables of the enclosing class
Only access to its own instance variables
Only access to its own instance variables inside a method
What statement is true about stream?
Stream operations do not mutate their source. Instead, they return new streams that hold the result
Stream operations are lazy whenever possible
All of the above
None of the above
What Are Streams?
From the API docs, A stream is “a sequence of elements supporting sequential and parallel aggregate operations
A Stream is no thing
Stream is only use for List
Stream is only use for Map
What statement is true?
we can obtain a Stream from any Collection object with a call to stream()
we can get a Stream from an array of objects using the static of method: Stream<int[]>strOfInt = Stream.of(arrOfInt)
All of the above
None of the above
What statement is true?
The call stream.limit(n) returns a new Stream that ends after n elements
The call stream.limit(n) returns a new Stream that ends after n-1 elements
The call stream.limit(n) returns two new Stream
The call stream.limit(n) returns no stream
What is the name for an implementation of a functional interface?
function
functor
comparator
compare
What is not true in the Benefits of the Functional Style?
Programs are more compact, easier to write, and easier to read/understand
Programs are thread-safe
Easier to demonstrate correctness of functional programs
It's a bad way of programming
What statement is true?
A Comparator is called a functional interface because it has just one (abstract) method
An implementation of a functional interface is called a functor
All of the above
None of the above
Which of the following is not step in the template for using stream?
Create stream
Create pipeline of operation
Implement interface
End with a termination
What is race condition?
Two and more threads have access to many objects and can modify the states of the objects
One thread has access to an object and can modify the state of the object
Many threads have access to the same object and each modifies the state of the object
None of the above
String in List<String> is called _______
A generic type invocation
A type argument
A parameterized type
A type variable
Which is pure function?
Date.now()
Math.random()
Math.abs()
None of the above
What is the higher-order function?
Returns a function as its result
Returns a value as its results
Take one or more function as arguments
1 & 3
Which is not a characteristic of pure function?
Always return the same output for the same input
Has no side effects
Parallelism
May modify the arguments which are passed to them
Which mechanism is using to create Thread in Java?
Extending the Thread class
Implementing the Runnable Interface
All of the above
None of the above
Which of following is not a side effect?
for loops
variable assignment
access current date
if/else statement
Which of these does Stream map() operates on?
Class
Interface
Predicate
Function
Do the stream operations like Filter(), Reduce(), Map() mutate existing stream?
Yes it mutates current stream and return it
No it creates a new stream and return it
These functions don't create or mutate stream
None of them
What Are Annotations?
Some kind of special functions in Java
Functional interfaces
Stream operations
Annotations are tags that are inserted into source code so that some tool can processthem
Which of the following functional interface represents a function that accepts an int- valued argument and produces a result?
IntConsumer
IntFunction<R>
IntPredicate
IntSupplier
Which of following is not true about functional interface in Java?
has just one (abstract) method
has String toString() method
must have @FunctionalInterface annotation
None of the above
Which of following operations are stateful transformations available from a Stream ?
limit
map
skip
sorted
We have two types of Streams in java 8 and are __________
Sequential and Parallel
Procedural and graphical
Object oriented and Fuctional programmimg
All of the above
Which is aggregate operation in Java 8?
filter
map
forEach
All of the above
What is the return type of lambda expression?
String
Function
Object oriented and Fuctional programmimg
void
What is Predicate in Java 8 ?
Methods
classes
Interfaces
All of the above
What is Predicate in Java 8 ?
To extract a substream that satisfies specified criteria
To transform each element of a stream
To remove duplicate elements
To transform each element to a stream and flatten the result
What is the best way of handling exceptions when your application uses external resources like files or a database connection?
Handling Exceptions with Try-catch Exception
Handling Exceptions with Try-with Resources
Handling Exceptions with Throw exemption
All of the above
Which of the following operation is a TERMINAL operation?
distinct()
sorted()
map()
collect()
In a stream pipeline which can return a value other than a Stream?
Source
Intermediate operation
Terminal operation
None of the above
Rewrite this lambda using a constructor reference n->new ArrayList<>(n):
ArrayList::new
ArrayList::new()
ArrayList::new(n)
ArrayList::new[n]
To get the first 10 elements of a stream apply
skip(10)
limit(10)
print(10)
concat(0->9)
Which one of the following interface is matched appropriately with its abstract method?
Predicate - accept ()
Consumer - test ()
Function - apply()
All of the above
Which one of the following is false?
Generic Subtyping Is Not Covariant
Array Subtyping Is Covariant
Generic methods introduce their own type parameters
None of the above
_________ is a way of representing data in a collection which supports functional-style operations to manipulate the data
Stream
UML
Generic
Map
What would be the output of the following Java code (Assume there is no compilation error and there is a comma between each string): System.out.println(Stream.of("gently" "down" "the" "stream").filter(x->x.length()>6).map(x- >x.toUpperCase()).collect(Collectors.toList()))
[gently stream]
[GENTLY STREAM]
[]
null
Which one of the following is not a side effect of a pure function in Java 8?
Variable assignment
Obtaining user input
For loops
None of the above
Which of the following is true about a funtional interface?
an interface that has only one abstract method
an interface with methods redeclared from the Object class only
can have more than one abstract methods
All of the above
What is the purpose of limit method of stream in java 8?
Iterate each element of the stream
Map each element to its corresponding result
Eliminate elements based on a criteria
Reduce the size of the stream
Which of the following is not terminal operation?
max
findFirst
findAny
reduce
One of the following is not true about filter?
Extracts a Substream that Satisfies Specified Criteria
accepts as its argument a Predicate interface
Used to transform each element of a Stream to another element
None of the above
Intermediate Operations are known as:
Functional interface
Lazy operations
Terminal operation
All of the above
Which of the following is correct about Java 8 lambda expression?
A lambda expression is a block of code with a list of formal parameters and a body
A lambda expression is a type of functional interface
All of the above
None of the above
Which statement is true about stream pipelining in Java 8?
Stream pipelining is the concept of chaining operations together
Each intermediate operation returns an instance of Stream itself when it runs
IT is set up to process data forming a processing pipeline
All of the above
Which defines the difference between flatMap() and map() functions?
flatMap() can be used to transform one object to another by applying a method on each element
flatMap() can flatten the Stream
All of the above
None of the above
What is the definition of a thread in Java?
A component of a process
An implementation of a process
An annotation of a process
An exception of a process
What is generic subtype of List<Cat> to List<Animal>?
co-variant
contra-variant
invariant
None of the above
What is advantage of functional style programming?
thread safe
easy to extend
using one super class
easy to implement to java
Which stream operation should not be done in parallel?
map
flatMap
collect
limit
