Java8 Innards Interview Question-Answer Part – 2

Q.1 If you wanted to process a stream of names, extract the male names, and store them in a new list, what is the appropriate operation to be used?

       A. Both Stream.reduce and Stream.collect

       B. Stream.collect

       C. Stream.reduce

       D. Stream.filter

Ans : Stream.collect

Q.2 Repeating annotations can be added with which of the following declarations?.

       A. Declare just the repeatable annotation type

       B. 1. Declare a repeatable annotation type
2. Declare the modifier annotation type

       C. 1. Declare a repeatable annotation type
2. Declare the containing annotation type

       D. None of the options

Ans : 1. Declare a repeatable annotation type
2. Declare the containing annotation type

Q.3 The terminal operation produces another stream as its output.

       A. True

       B. False

Ans : False

Q.4 Optional type validation can be used to substitute runtime validations.

       A. True

       B. False

Ans : False

Q.5 Repeating annotations can be retrieved using _________

       A. getAnnotationsList()

       B. getAnnotations()

       C. getAnnotationsByType()

       D. getAnnotationsByValue()

Ans : getAnnotationsByType()

Q.6 On which of these can annotations be used on in Java 8?

       A. Local variables

       B. Super classes

       C. Generic types

       D. All the options

Ans : All the options

Q.7 Type annotation is used to depict the non-blank string value _________

       A. @NotBlank

       B. @NotEmpty

       C. @NonBlank

       D. None of the options

Ans : @NotBlank

Q.8 LocalDate date1 =;
LocalDate date2 =, ChronoUnit.MONTHS);
Period period = Period.between(date2, date1);
System.out.println(“Period: ” + period);

Choose the correct output.

       A. Compilation error

       B. Period: P-1M

       C. Period: 1

       D. Runtime error

Ans : Period: P-1M

Q.9 Which method is used to connect the consumer to the source in reactive programming?

       A. connectTo()

       B. subscribe()

       C. subscribeTo()

       D. connect()

Ans : subscribe()

Q.10 The method used to fetch the parameter types using method parameter reflection is _________.

       A. getParameterizedTypes()

       B. getTypeParam()

       C. getParamType()

       D. getParameterizedType()

Ans : getParameterizedType()

Q.11 Which of these should be used to show package-level and class-level dependencies of Class files in Java 8?

       A. dep

       B. jdeps

       C. ideps

       D. jdep

Ans : jdeps

Q.12 Which of the following methods preserve parameter names in Java bytecode (through reflection API)?

       A. All public methods

       B. All methods

       C. specify -parameters during compilation

       D. specify -params during compilation

Ans : All public methods

Q.13 Reactive Programming deals with ____________.

       A. Synchronous data

       B. Asynchronous data

       C. Both the options

       D. None of the options

Ans : Asynchronous data

Q.14 Identify the intermediate and terminal operations in the code.

double average = roster
  .filter(p -> p.getGender() == Person.Sex.MALE)

       A. Intermediate: filter, mapToInt Terminal: average

       B. Intermediate: filter Terminal: mapToInt, average

       C. Intermediate:average Terminal: filter, mapToInt

       D. Intermediate: filter, mapToInt Terminal: getAsDouble

Ans : Intermediate: filter, mapToInt Terminal: average

Leave a Comment