wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Final

Total questions: 98

Worksheet time: 3hrs 16mins

Name
Class
Date
1.

What is a best practice for unit testing when lambdas are involved?

a)

Replace a lambda that needs to be tested with a method reference

b)

Test an auxiliary method

c)

1 & 2

d)

None of the above

2.

Which one of the following stream operations is NOT stateless operation?

a)

map

b)

filter

c)

sorted

d)

limit

3.

Which function to Transform Each Element of a Stream?

a)

filter

b)

map

c)

reduce

d)

collect

4.

Lambda expressions are used primarily to define inline implementation of a functional interface

a)

True

b)

False

5.

What can help us in avoiding NullPointeExceptions and null checks in java 8?

a)

Optional

b)

Required

c)

NotNull

d)

NotRequired

6.

Predicate is in which package in Java 8?

a)

java.util.predicate

b)

java.util.object

c)

java.util.objects

d)

java.util.predict

7.

What is an implementation of a functional interface called?

a)

Lambda expression

b)

Functor

c)

Comparator

d)

Implementation

8.

What is stream in java 8?

a)

Stream represents a sequence of objects from a source ,which supports aggregate operations

b)

Stream can be used only to model object oriented systems

c)

Stream represent associations represent methods

d)

All of the above

9.

What is the difference between Streams and Collections?

a)

Stream operations do iteration internally and Collections operations to iteration explicitly

b)

Stream operations do iteration explicitly and Collections operations to iteration internally

c)

Stream operations do iteration internally and external and Collections operations to iteration only explicitly

d)

None of the above

10.

A method used to eliminate elements based on criteria

a)

stream

b)

filter

c)

map

d)

reduce

11.

What is optional in java 8?

a)

Optional object is used to represents boolean with absent value

b)

Optional object is to used represent only integer with absent value

c)

Optional is a container object which represents not- null objects

d)

Optional object is used to represent only Strings with absent value

12.

A method used to combine the result of prosessing on the elements of stream

a)

stream

b)

filter

c)

flatMap

d)

Collectors

13.

Which of the following is the purpose of limit method in Java?

a)

to concat the stream

b)

to reduce the limit of stream

c)

to sum up the stream

d)

All of the above

14.

What is the purpose of Predicate<T> Functional Interface?

a)

It represents a super Type

b)

It represents the subtype

c)

It represents a predicate (Boolean -valued - function) of two argument

d)

It represents a predicate (Boolean -valued - function) of one argument

15.

Which one is true about Streams?

a)

Do not store elements they operate on

b)

Do not mutate their source

c)

Stream operations are lazy when ever possible

d)

All of the above

16.

Which of the following operation can concatenate two streams?

a)

Concat.stream(Stream,Stream)

b)

Stream.concat(Stream,Stream)

c)

Stream.concat(Stream)

d)

Stream.concat()

17.

Which of the following operation combine the terms of a stream into a single value by repeatedly applying an operation?

a)

Reduce

b)

Collector

c)

Filter

d)

All of the above

18.

Which of the following best describes @FunctionalInterface?

a)

Has two method

b)

Has only one method

c)

Has no method

d)

All of the above

19.

Which of the following operation is true about stream.skip(n) ?

a)

Discards the first n elements

b)

Discards the last n elements

c)

Discards half of n elements

d)

None of the above

20.

Which of the following is true about singleton implementation?

a)

It is thread safe

b)

It is not thread safe

c)

Sometimes It is thread safe

d)

None of the above

21.

Which of the following are benefits of Functional style programming?

a)

Programs are compact and easy to read

b)

Programs are thread safe

c)

Easier to test

d)

All of the above

22.

What is the Free variable?

a)

Variables that are passed as arguments in the lambda expression

b)

Variables that are not parameters and not defined inside the block of code

c)

It's not related to funcional programming concepts

d)

None of the above

23.

Which of the following can be a side effect for pure function?

a)

Variable assignment

b)

Making an http call

c)

For loops

d)

All of the above

24.

The newly introduced Streams API is available in which package of Java 8?

a)

java.io.streams

b)

java.io.stream

c)

java.util.streams

d)

java.util.stream

25.

Lambda expressions in java 8 are based on _________

a)

Procedural programming

b)

Functional programming

c)

Data programming

d)

All of the above

26.

Stream operations in java 8 can be divided into __________

a)

Terminal types

b)

Intermediate types

c)

All of the above

d)

None of the above

27.

In java 8 R apply(T t) is a method of ________

a)

Function

b)

Process

c)

Predicate

d)

None of the above

28.

Which of the following is not terminal operation?

a)

filter

b)

count

c)

collect(Collectors.to list())

d)

None of the above

29.

What is the Optional object used for?

a)

Optional is used for optional runtime argument

b)

Optional is used for optional spring profile

c)

Optional is used to represent null with absent value

d)

Optional means its not mandatory for method to return object

30.

Which of the following is the most useful while working with parallel streams?

a)

findAny

b)

findFirst

c)

distinct

d)

None of the above

31.

A TriFunction _________

a)

takes one argument and returns two

b)

takes two arguments and returns one

c)

takes three arguments and returns one

d)

takes two arrguments and returns two

32.

Which is not true for a pure function?

a)

It has same output for same input everytime

b)

It does not have any side effects

c)

It is not necessarily defined for every input

d)

Many inputs can have same output

33.

The higher order function in a stream filter should always return ___________

a)

boolean

b)

same instance as instance of argument

c)

anything

d)

long

34.

Which is the correct way to execute a functional interface?

a)

func.bind

b)

func.call

c)

func.apply

d)

func

35.

A piece of code to carry state from a defining context to an execution context is called a __________

a)

lambda

b)

closure

c)

Anonymous function

d)

pure function

36.

What is the correct way to handle exceptions in a stream execution?

a)

Handle it globally in the main method

b)

Handle the appropriate exception inside the higher order function block and then raisea runtimeexception

c)

Adjust your code to not throw exceptions at all

d)

We do not need to handle exceptions in streams

37.

Button::new can be resolved by the following lambda expression str -> new Button(str)

a)

True

b)

False

38.

map() is one of the terminal operation operations

a)

True

b)

False

39.

filter() is an intermideate operation used to

a)

extract subtypes which satisfy a certain condition

b)

change datatype

c)

concat two strings

d)

None of the above

40.

filter() returns ___________

a)

Only int values

b)

Only String values

c)

it is void

d)

another stream

41.

count() is a user defined or implemented method

a)

True

b)

False

42.

Which one is true about functional programming?

a)

we get the same output for any input

b)

it is pure OOP

c)

it is inheritance

d)

None of the above

43.

we can stream with in stream

a)

True

b)

False

44.

Benefit of generics can be attributed to _________

a)

Stronger type checks at compile time

b)

Reduce downcasting

c)

Supports the most general possible API for methods

d)

All of the above

45.

In the terminology and naming convention of Generics it is found List<T> where?

a)

T is an element from the Java Collections Framework

b)

T is a type

c)

T is a key

d)

T is a value

46.

Advantages of functional programing rely on?

a)

Purely functional -so threadsafe

b)

Makes no commitments to an interaction path -so more parallelizable

c)

Declaratice style -what and not how

d)

All of the above

47.

Facts about Streams in functional programming can be considered as?

a)

Streams do no store elements they operate on

b)

Streams do not mutate their source

c)

Java implementation involve a combination of technical operations

d)

All of the above

48.

Collecting results is considered in a Stream?

a)

An intermediate operation

b)

A terminal operation

c)

A stateful intermediate operation

d)

A creating operation

49.

How many INPUT arguments does the functional interface TriFunction<S T R U> accept?

a)

Three input and produces one output

b)

Two input and produces two output

c)

One input and produces three output

d)

Four input and produces zero output

50.

Are local and anonymous inner classes allowed to?

a)

Access to Instance variables of the enclosing class

b)

Not access to Instance variables of the enclosing class

c)

Only access to its own instance variables

d)

Only access to its own instance variables inside a method

51.

What statement is true about stream?

a)

Stream operations do not mutate their source. Instead, they return new streams that hold the result

b)

Stream operations are lazy whenever possible

c)

All of the above

d)

None of the above

52.

What Are Streams?

a)

From the API docs, A stream is “a sequence of elements supporting sequential and parallel aggregate operations

b)

A Stream is no thing

c)

Stream is only use for List

d)

Stream is only use for Map

53.

What statement is true?

a)

we can obtain a Stream from any Collection object with a call to stream()

b)

we can get a Stream from an array of objects using the static of method: Stream<int[]>strOfInt = Stream.of(arrOfInt)

c)

All of the above

d)

None of the above

54.

What statement is true?

a)

The call stream.limit(n) returns a new Stream that ends after n elements

b)

The call stream.limit(n) returns a new Stream that ends after n-1 elements

c)

The call stream.limit(n) returns two new Stream

d)

The call stream.limit(n) returns no stream

55.

What is the name for an implementation of a functional interface?

a)

function

b)

functor

c)

comparator

d)

compare

56.

What is not true in the Benefits of the Functional Style?

a)

Programs are more compact, easier to write, and easier to read/understand

b)

Programs are thread-safe

c)

Easier to demonstrate correctness of functional programs

d)

It's a bad way of programming

57.

What statement is true?

a)

A Comparator is called a functional interface because it has just one (abstract) method

b)

An implementation of a functional interface is called a functor

c)

All of the above

d)

None of the above

58.

Which of the following is not step in the template for using stream?

a)

Create stream

b)

Create pipeline of operation

c)

Implement interface

d)

End with a termination

59.

What is race condition?

a)

Two and more threads have access to many objects and can modify the states of the objects

b)

One thread has access to an object and can modify the state of the object

c)

Many threads have access to the same object and each modifies the state of the object

d)

None of the above

60.

String in List<String> is called _______

a)

A generic type invocation

b)

A type argument

c)

A parameterized type

d)

A type variable

61.

Which is pure function?

a)

Date.now()

b)

Math.random()

c)

Math.abs()

d)

None of the above

62.

What is the higher-order function?

a)

Returns a function as its result

b)

Returns a value as its results

c)

Take one or more function as arguments

d)

1 & 3

63.

Which is not a characteristic of pure function?

a)

Always return the same output for the same input

b)

Has no side effects

c)

Parallelism

d)

May modify the arguments which are passed to them

64.

Which mechanism is using to create Thread in Java?

a)

Extending the Thread class

b)

Implementing the Runnable Interface

c)

All of the above

d)

None of the above

65.

Which of following is not a side effect?

a)

for loops

b)

variable assignment

c)

access current date

d)

if/else statement

66.

Which of these does Stream map() operates on?

a)

Class

b)

Interface

c)

Predicate

d)

Function

67.

Do the stream operations like Filter(), Reduce(), Map() mutate existing stream?

a)

Yes it mutates current stream and return it

b)

No it creates a new stream and return it

c)

These functions don't create or mutate stream

d)

None of them

68.

What Are Annotations?

a)

Some kind of special functions in Java

b)

Functional interfaces

c)

Stream operations

d)

Annotations are tags that are inserted into source code so that some tool can processthem

69.

Which of the following functional interface represents a function that accepts an int- valued argument and produces a result?

a)

IntConsumer

b)

IntFunction<R>

c)

IntPredicate

d)

IntSupplier

70.

Which of following is not true about functional interface in Java?

a)

has just one (abstract) method

b)

has String toString() method

c)

must have @FunctionalInterface annotation

d)

None of the above

71.

Which of following operations are stateful transformations available from a Stream ?

a)

limit

b)

map

c)

skip

d)

sorted

72.

We have two types of Streams in java 8 and are __________

a)

Sequential and Parallel

b)

Procedural and graphical

c)

Object oriented and Fuctional programmimg

d)

All of the above

73.

Which is aggregate operation in Java 8?

a)

filter

b)

map

c)

forEach

d)

All of the above

74.

What is the return type of lambda expression?

a)

String

b)

Function

c)

Object oriented and Fuctional programmimg

d)

void

75.

What is Predicate in Java 8 ?

a)

Methods

b)

classes

c)

Interfaces

d)

All of the above

76.

What is Predicate in Java 8 ?

a)

To extract a substream that satisfies specified criteria

b)

To transform each element of a stream

c)

To remove duplicate elements

d)

To transform each element to a stream and flatten the result

77.

What is the best way of handling exceptions when your application uses external resources like files or a database connection?

a)

Handling Exceptions with Try-catch Exception

b)

Handling Exceptions with Try-with Resources

c)

Handling Exceptions with Throw exemption

d)

All of the above

78.

Which of the following operation is a TERMINAL operation?

a)

distinct()

b)

sorted()

c)

map()

d)

collect()

79.

In a stream pipeline which can return a value other than a Stream?

a)

Source

b)

Intermediate operation

c)

Terminal operation

d)

None of the above

80.

Rewrite this lambda using a constructor reference n->new ArrayList<>(n):

a)

ArrayList::new

b)

ArrayList::new()

c)

ArrayList::new(n)

d)

ArrayList::new[n]

81.

To get the first 10 elements of a stream apply

a)

skip(10)

b)

limit(10)

c)

print(10)

d)

concat(0->9)

82.

Which one of the following interface is matched appropriately with its abstract method?

a)

Predicate - accept ()

b)

Consumer - test ()

c)

Function - apply()

d)

All of the above

83.

Which one of the following is false?

a)

Generic Subtyping Is Not Covariant

b)

Array Subtyping Is Covariant

c)

Generic methods introduce their own type parameters

d)

None of the above

84.

_________ is a way of representing data in a collection which supports functional-style operations to manipulate the data

a)

Stream

b)

UML

c)

Generic

d)

Map

85.

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()))

a)

[gently stream]

b)

[GENTLY STREAM]

c)

[]

d)

null

86.

Which one of the following is not a side effect of a pure function in Java 8?

a)

Variable assignment

b)

Obtaining user input

c)

For loops

d)

None of the above

87.

Which of the following is true about a funtional interface?

a)

an interface that has only one abstract method

b)

an interface with methods redeclared from the Object class only

c)

can have more than one abstract methods

d)

All of the above

88.

What is the purpose of limit method of stream in java 8?

a)

Iterate each element of the stream

b)

Map each element to its corresponding result

c)

Eliminate elements based on a criteria

d)

Reduce the size of the stream

89.

Which of the following is not terminal operation?

a)

max

b)

findFirst

c)

findAny

d)

reduce

90.

One of the following is not true about filter?

a)

Extracts a Substream that Satisfies Specified Criteria

b)

accepts as its argument a Predicate interface

c)

Used to transform each element of a Stream to another element

d)

None of the above

91.

Intermediate Operations are known as:

a)

Functional interface

b)

Lazy operations

c)

Terminal operation

d)

All of the above

92.

Which of the following is correct about Java 8 lambda expression?

a)

A lambda expression is a block of code with a list of formal parameters and a body

b)

A lambda expression is a type of functional interface

c)

All of the above

d)

None of the above

93.

Which statement is true about stream pipelining in Java 8?

a)

Stream pipelining is the concept of chaining operations together

b)

Each intermediate operation returns an instance of Stream itself when it runs

c)

IT is set up to process data forming a processing pipeline

d)

All of the above

94.

Which defines the difference between flatMap() and map() functions?

a)

flatMap() can be used to transform one object to another by applying a method on each element

b)

flatMap() can flatten the Stream

c)

All of the above

d)

None of the above

95.

What is the definition of a thread in Java?

a)

A component of a process

b)

An implementation of a process

c)

An annotation of a process

d)

An exception of a process

96.

What is generic subtype of List<Cat> to List<Animal>?

a)

co-variant

b)

contra-variant

c)

invariant

d)

None of the above

97.

What is advantage of functional style programming?

a)

thread safe

b)

easy to extend

c)

using one super class

d)

easy to implement to java

98.

Which stream operation should not be done in parallel?

a)

map

b)

flatMap

c)

collect

d)

limit