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.6Medium

Which of the following lambda expressions is invalid?

Q.7Medium

What is the type of the following lambda expression: x -> x.length()?

Q.8Medium

Which functional interface should be used for a lambda that filters elements?

Q.9Medium

What will this code print? List<Integer> list = Arrays.asList(1, 2, 3, 4, 5); list.forEach(x -> System.out.print(x + " "));

Q.10Medium

Can lambda expressions access local variables from their enclosing scope?

Q.11Medium

Which of the following correctly represents a BiFunction?

Q.12Medium

What is the difference between a lambda expression and an anonymous inner class?

Q.13Hard

What will be the output of this nested lambda? Function<Integer, Function<Integer, Integer>> add = x -> y -> x + y; System.out.println(add.apply(3).apply(5));

Q.14Medium

Which of the following statements about @FunctionalInterface is true?

Q.15Easy

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

Q.16Medium

Can a lambda expression have multiple statements in its body?

Q.17Medium

Which functional interface is best suited for this scenario: method that takes no parameters and returns a random number?

Q.18Hard

What will happen if you try to compile this code? BiFunction<String, String, String> concat = (a, b) -> a + b; concat.apply("Java", "8", "Features");

Q.19Medium

In Java streams, what does the filter() method use?

Q.20Hard

What is the type inference mechanism in lambda expressions?