0 votes
in JAVA by
Java8 Innards Interview Questions and Answers from Fresco Play

java 8 innards hackerrank solution

java 8 innards date and time api zone class

java 8 innards fresco play mcq

1 Answer

0 votes
by
edited by

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

a) Optional parenthesis around parameter – There is no need to declare a single parameter in parenthesis. For multiple parameters, parentheses are required.

b) Optional type declaration – There is no need to declare the type of a parameter. The compiler can infer the same from the value of the parameter.

c) Both the options

d) None of the options

Correct Answer is - Both the options

Question#2 Lambda expressions in Java allow us to treat ___________.

a) Data as code

b) Code as data

c) Both the options

d) None of the options

Correct Answer is - Code as data

Question#3 Object o = () -> {System.out.println(“Example”); };

Object o can be replaced with?

a) Function f

b) Runnable r

c) Consumer c

d) All the options

Correct Answer is - Runnable r

Question#4 The following are valid lambda expressions, except _________.

a) () -> {return “Mario”;}

b) () -> “Raoul”

c) () -> {}

d) None of the options

Correct Answer is - None of the options

Question#5 public class Main{

  public static void main(String [] args){

    String name=”WelcomeJava”;

     Runnable r1=() -> System.out.println(name);

    String name1 = name.toUpperCase();

    Runnable r2=() -> System.out.println(name1);

     r1.run();

  }

}

What is the output of the above program?

a) WELCOMEJAVA

b) WelcomeJava

c) Runtime error

d) Compilation error

Correct Answer is - WelcomeJava

Question#6 The following lambda expression is valid.

(x, y) -> return x + y

a) True

b) False

Correct Answer is - True

Question#7 Parameter types can be inferred in Lambda expressions.

a) True

b) False

Correct Answer is - True

Question#8 Which of the following is a valid use of lambda expressions?

a) public void execute(Runnable r){ r.run(); } Execute(() -> {});

b) Predicate p = (Apple a) -> a.getWeight(); public interface Predicate { boolean predicate(T t); }

c) public Callable fetch() { Return ? “Tricky example ;-)”; }

d) All the options

Correct Answer is - public void execute(Runnable r){ r.run(); } Execute(() -> {});

Question#9 Lambda expressions are based on __________

a) Procedural Programming

b) Data Programming

c) Functional Programming

d) All the options

Correct Answer is - Functional Programming

Question#10 Which of the following functional interfaces represents an operation that accepts an object-valued and an int-valued argument, and returns no result?

a) Predicate<T>

b) ObjIntConsumer<T>

c) ObjLongConsumer<T>

d) Supplier<T>

Correct Answer is - ObjIntConsumer<T>

Question#11 Which of the following interfaces is a functional interface?

a) public interface NewCards extends Cards{ int totalCount(double a, double b); }

b) public interface InvalidCard{ }

c) public interface Cards{ int totalCount(int a, int b); }

Correct Answer is - public interface Cards{ int totalCount(int a, int b); }

Question#12 Which of the following functional interfaces represents an operation upon two long-valued operands and produces a long-valued result?

a) IntUnaryOperator

b) IntToDoubleFunction

c) LongBinaryOperator

d) LongToLongFunction

Correct Answer is - LongBinaryOperator

Question#13 Which functional interface would you use for the following: No parameters, returns a value.

a) Consumer

b) BiConsumer

c) BiSupplier

d) Supplier

Correct Answer is - Supplier

Question#14 A functional interface acts as a target type for which of the following?

a) Method reference

b) Constructor reference

c) Lambda expression

d) All the options

Correct Answer is - All the options

Question#15 Which of the following functional interfaces represents an operation that accepts a single input argument and returns no result?

a) BooleanSupplier

b) DoubleBinaryOperator

c) DoubleConsumer

d) Consumer<T>

Correct Answer is - Consumer<T>

Question#16 A FunctionalInterface annotation (@FunctionalInterface) is necessary for making an interface a functional interface.

a) True

b) False

Correct Answer is - False

Question#17 The following code includes a valid Functional Interface.

package functionalInterfaceExample;@FunctionalInterface

public interface MyFirstFunctionalInterface {

public void firstWork();

@Override

public String toString();

@Override

public boolean equals(Object obj);

}

a) True

b) False

Correct Answer is - True

Question#18 Which of the following functional interfaces represents a function that accepts an int-valued argument and produces a long-valued result?

a) IntToLongFunction

b) LongBinaryOperator

c) IntLongOperator

d) IntToDoubleFunction

Correct Answer is - IntToLongFunction

Question#19 Which of the following functional interfaces represents an operation upon two long-valued operands and produces a long-valued result?

a) LongToLongFunction

b) IntToDoubleFunction

c) IntUnaryOperator

d) LongBinaryOperator

Correct Answer is - LongBinaryOperator

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

a) java.io.streams

b) java.util.streams

c) java.util.stream

d) java.io.stream

Correct Answer is - java.util.stream

Question#21 Which of the following is a valid Stream operation type?

a) Intermediate operation

b) Terminal operation

c) Both the options

d) None of the options

Correct Answer is - Both the options

Question#22 Stream operations in Java 8 can be divided into __________.

a) Intermediate types

b) Terminal types

c) None of the options

d) All the options

Correct Answer is - All the options

Question#23 Each pipeline ends with a/an ____________.

a) Intermediate operation

b) Terminal operation

c) Short circuit operation

d) Any of the options

Correct Answer is - Terminal operation

Question#24 Which of these does Stream filter() operates on?

a) Methods

b) Predicate

c) Interface

d) Class

Correct Answer is - Predicate

Question#25 Stream operation iterations are internal over the source of elements.

a) True

b) False

Correct Answer is - False

More Questions on Java8 

Question#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

Answer:-Stream.collect

Question#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

Answer:-1. Declare a repeatable annotation type

2. Declare the containing annotation type

Question#3 The terminal operation produces another stream as its output.

a) True

b) False

Answer:-False

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

a) True

b) False

Answer:-False

Question#5 Repeating annotations can be retrieved using _________

a) getAnnotationsList()

b) getAnnotations()

c) getAnnotationsByType()

d) getAnnotationsByValue()

Answer:-getAnnotationsByType()

Question#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

Answer:-All the options

Question#7 Type annotation is used to depict the non-blank string value _________

a) @NotBlank

b) @NotEmpty

c) @NonBlank

d) None of the options

Answer:-@NotBlank

Question#8 LocalDate date1 = LocalDate.now();

LocalDate date2 = date1.plus(1, 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

Answer:-Period: P-1M

Question#9 Which method is used to connect the consumer to the source in reactive programming?

a) connectTo()

b) subscribe()

c) subscribeTo()

d) connect()

Answer:-subscribe()

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

a) getParameterizedTypes()

b) getTypeParam()

c) getParamType()

d) getParameterizedType()

Answer:-getParameterizedType()

Question#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

Answer:-jdeps

Question#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

Answer:-All public methods

Question#13 Reactive Programming deals with ____________.

a) Synchronous data

b) Asynchronous data

c) Both the options

d) None of the options

Answer:-Asynchronous data

Question#14 Identify the intermediate and terminal operations in the code.

double average = roster

  .stream()

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

  .mapToInt(Person::getAge)

  .average()

  .getAsDouble();

a) Intermediate: filter, mapToInt Terminal: average

b) Intermediate: filter Terminal: mapToInt, average

c) Intermediate:average Terminal: filter, mapToInt

d) Intermediate: filter, mapToInt Terminal: getAsDouble

Answer:-Intermediate: filter, mapToInt Terminal: average

...