Java 8 Mock Test


Advertisements

This section presents you various set of Mock Tests related to Java 8. You can download these sample mock tests at your local machine and solve offline at your convenience. Every mock test is supplied with a mock test key to let you verify the final score and grade yourself.

Questions and Answers

Java 8 Mock Test IV

Q 1 - Which of the following method of Base64 class returns a Base64.Encoder that encodes using the URL and Filename safe type base64 encoding scheme?

A - getUrlDecoder()

B - getUrlEncoder()

C - getMimeDecoder()

D - getMimeEncoder

Answer : B

Explanation

getUrlEncoder() method of Base64 class returns a Base64.Encoder that encodes using the URL and Filename safe type base64 encoding scheme.

Q 2 - Which of the following is the correct lambda expression which add two numbers and return their sum?

A - (int a, int b) -> a + b;

B - (a, b) -> a + b

C - Both of the above.

D - None of the above.

Answer : C

Explanation

Both of the above options are correct.

Q 3 - Which of the following is the correct lambda expression which add two numbers and return their sum?

A - (int a, int b) -> { return a + b;};

B - (a, b) -> {return a + b;};

C - Both of the above.

D - None of the above.

Answer : C

Explanation

Both of the above options are correct.

Q 4 - Lambda expressions are used primarily to define inline implementation of a functional interface.

A - true

B - false

Answer : A

Explanation

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

Q 5 - Using lambda expression, you can refer to final variable or effectively final variable (which is assigned only once).

A - false

B - true

Answer : B

Explanation

Using lambda expression, you can refer to final variable or effectively final variable (which is assigned only once).

Q 6 - Method references help to point to methods by their names.

A - true

B - false

Answer : A

Explanation

Method references help to point to methods by their names.

Q 7 - A method reference is described using :: (double colon) symbol.

A - false

B - true

Answer : B

Explanation

A method reference is described using :: (double colon) symbol.

Q 8 - Functional interfaces have a single functionality to exhibit.

A - false

B - true

Answer : B

Explanation

Functional interfaces have a single functionality to exhibit.

Q 9 - A stream provides a set of elements of specific type in a sequential manner.

A - true

B - false

Answer : A

Explanation

A stream provides a set of elements of specific type in a sequential manner. A stream gets/computes elements on demand. It never stores the elements.

Q 10 - Stream takes Collections, Arrays, or I/O resources as input source.

A - true

B - false

Answer : A

Explanation

Stream takes Collections, Arrays, or I/O resources as input source.

Q 11 - Stream supports aggregate operations like filter, map, limit, reduce, find and match.

A - false

B - true

Answer : B

Explanation

Stream supports aggregate operations like filter, map, limit, reduce, find, match, and so on.

Q 12 - Most of the stream operations return stream itself so that their result can be pipelined.

A - false

B - true

Answer : B

Explanation

Most of the stream operations return stream itself so that their result can be pipelined.

Q 13 - Stream operations do the iterations internally over the source elements provided.

A - false

B - true

Answer : B

Explanation

Stream operations do the iterations internally over the source elements provided, in contrast to Collections where explicit iteration is required.

Q 14 - Optional is a container object which is used to contain not-null objects.

A - true

B - false

Answer : A

Explanation

Optional is a container object which is used to contain not-null objects.

Q 15 - Optional object is used to represent non null value with absent value.

A - true

B - false

Answer : B

Explanation

Optional object is used to represent null with absent value.

Q 16 - Optional.ofNullable method allows passed parameter to be null.

A - true

B - false

Answer : A

Explanation

Optional.ofNullable method allows passed parameter to be null.

Q 17 - Optional.of method throws NullPointerException if passed parameter is null.

A - true

B - false

Answer : A

Explanation

Optional.of method throws NullPointerException if passed parameter is null.

Q 18 - Optional.isPresent method checks the value is present or not.

A - false

B - true

Answer : B

Explanation

Optional.isPresent method checks the value is present or not.

Q 19 - Optional.orElse method returns the value if present otherwise returns the default value passed.

A - false

B - true

Answer : B

Explanation

Optional.orElse method returns the value if present otherwise returns the default value passed.

Q 20 - Optional.get method gets the value, value should be present.

A - false

B - true

Answer : B

Explanation

Optional.get method gets the value, value should be present.

Q 21 - java.util.Date is not thread safe, thus developers have to deal with concurrency issue while using date.

A - true

B - false

Answer : A

Explanation

java.util.Date is not thread safe, thus developers have to deal with concurrency issue while using date.

Q 22 - The new date-time API in java 8 is immutable and does not have setter methods.

A - true

B - false

Answer : A

Explanation

The new date-time API in java 8 is immutable and does not have setter methods.

Q 23 - In which of the following type of Base64 encoding, Output is mapped to a set of characters lying in A-Za-z0-9+/?

A - Simple

B - URL

C - MIME

D - None of the above.

Answer : A

Explanation

Simple − Output is mapped to a set of characters lying in A-Za-z0-9+/.

Q 24 - In which of the following type of Base64 encoding, Output is mapped to a set of characters lying in A-Za-z0-9+_?

A - Simple

B - URL

C - MIME

D - None of the above.

Answer : B

Explanation

URL − Output is mapped to a set of characters lying in A-Za-z0-9+_.

Q 25 - In which of the following type of Base64 encoding, Output is mapped to MIME friendly format?

A - Simple

B - URL

C - MIME

D - None of the above.

Answer : C

Explanation

MIME − Output is mapped to MIME friendly format. Output is represented in lines of no more than 76 characters each, and uses a carriage return ' ' followed by a linefeed ' ' as the line separator. No line separator is present to the end of the encoded output.

Answer Sheet

Question Number Answer Key
1 B
2 C
3 C
4 A
5 B
6 A
7 B
8 B
9 A
10 A
11 B
12 B
13 B
14 A
15 B
16 A
17 A
18 B
19 B
20 B
21 A
22 A
23 A
24 B
25 C
java8_questions_answers.htm
Advertisements