---Advertisement---
Java8 Innards Microservices

Java8 Innards Interview Question-Answer

By smart_answer13

Updated on:

---Advertisement---

Q.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

Ans : Both the options


Q.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

Ans : Code as data


Q.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

Ans : Runnable r


Q.4 The following are valid lambda expressions, except _________.

       A. () -> {return “Mario”;}

       B. () -> “Raoul”

       C. () -> {}

       D. None of the options

Ans : None of the options


Q.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

Ans : WelcomeJava


Q.6 The following lambda expression is valid.
(x, y) -> return x + y

       A. True

       B. False

Ans : True


Q.7 Parameter types can be inferred in Lambda expressions.

       A. True

       B. False

Ans : True


Q.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

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


Q.9 Lambda expressions are based on __________

       A. Procedural Programming

       B. Data Programming

       C. Functional Programming

       D. All the options

Ans : Functional Programming


Q.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>

Ans : ObjIntConsumer<T>


Q.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); }

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


Q.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

Ans : LongBinaryOperator


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

       A. Consumer

       B. BiConsumer

       C. BiSupplier

       D. Supplier

Ans : Supplier


Q.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

Ans : All the options


Q.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>

Ans : Consumer<T>


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

       A. True

       B. False

Ans : False


Q.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

Ans : True


Q.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

Ans : IntToLongFunction


Q.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

Ans : LongBinaryOperator


Q.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

Ans : java.util.stream


Q.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

Ans : Both the options


Q.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

Ans : All the options


Q.23 Each pipeline ends with a/an ____________.

       A. Intermediate operation

       B. Terminal operation

       C. Short circuit operation

       D. Any of the options

Ans : Terminal operation


Q.24 Which of these does Stream filter() operates on?

       A. Methods

       B. Predicate

       C. Interface

       D. Class

Ans : Predicate


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

       A. True

       B. False

Ans : False


smart_answer13

---Advertisement---

Related Post

Zipkin-Jaeger Interview Question-Answer

Q.1 Which is responsible for sending spans to storage?        A. Transport        B. Collector        C. Component        D. ...

Weaveworks Interview Question-Answer

Q.1 Which of the following features offered by WeaveClouds?        A. Observability        B. VCS integration        C. none of the mentioned ...

Vaadin Unplugged Interview Question-Answer

Q.1 Which of the Programming Model is not supported by Vaadin?        A. Browser        B. Client Side        C. Server Side ...

Spring Boot Framework Interview Question-Answer Part – 2

Q.1 The annotation used to import additional configuration classes is ___________.        A. @Import        B. @Include        C. @EnableImport     ...

Leave a Comment