iGET

Java Programming - MCQ Practice Questions

Practice free Java Programming multiple-choice questions with detailed answers and explanations. Perfect for competitive exam preparation.

958 questions | 100% Free

Q.1Easy

What is the primary purpose of lambda expressions introduced in Java 8?

Q.2Easy

Which of the following is a valid lambda expression syntax in Java?

Q.3Easy

What is a functional interface in Java?

Q.4Easy

Which package contains the built-in functional interfaces in Java?

Q.5Easy

What will be the output of the following code? UnaryOperator<Integer> square = x -> x * x; System.out.println(square.apply(5));

Q.6Easy

What is the output of this code? Consumer<String> print = s -> System.out.println(s.toUpperCase()); print.accept("java");

Q.7Easy

In Java 8, a lambda expression can access local variables from its enclosing scope. What is the constraint on these variables?

Q.8Easy

What is the return type of the map() method when used with lambda expressions in Java Streams?

Q.9Easy

Consider the code: List<String> names = Arrays.asList("Raj", "Priya", "Amit"); names.forEach(n -> System.out.println(n)); What does this code do?

Q.10Easy

Which functional interface is used for operations that take no arguments and return a value?

Q.11Easy

What is the primary advantage of using lambda expressions in Java 8+?

Q.12Easy

What will be the output of: List<String> list = Arrays.asList("a", "bb", "ccc"); list.forEach(s -> System.out.print(s.length() + " "));

Q.13Easy

Which functional interface is used for operations that take two arguments and return a single value?

Q.14Easy

What is a method reference (::) in Java?

Q.15Easy

What is the purpose of the @FunctionalInterface annotation in Java?

Q.16Easy

Which stream operation would you use to transform elements from one type to another?

Q.17Easy

Which of the following is a valid lambda expression in Java?

Q.18Easy

A lambda expression can only be used with which type of interface?

Q.19Easy

What is the return type of the lambda expression: (a, b) -> a > b?

Q.20Easy

What is the output of: BiFunction<Integer, Integer, Integer> add = (a, b) -> a + b; System.out.println(add.apply(5, 3));