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.81Easy

What is the purpose of a Predicate functional interface in Java?

Q.82Medium

Consider the code: List<String> names = Arrays.asList("Alice", "Bob"); names.forEach(name -> System.out.println(name)); What type of functional interface is used in forEach?

Q.83Medium

What is the output of: List<Integer> nums = Arrays.asList(1,2,3); nums.stream().filter(x -> x > 1).forEach(System.out::println);

Q.84Medium

Which lambda expression correctly implements a custom functional interface: public interface Math { int calculate(int a, int b); }

Q.85Easy

In a lambda expression, what does the arrow (->) operator represent?

Q.86Medium

Consider: Comparator<Integer> comp = (a, b) -> b - a; List<Integer> list = Arrays.asList(3,1,2); Collections.sort(list, comp); What is the result?

Q.87Medium

Which of the following correctly uses a method reference as an alternative to a lambda expression?

Q.88Easy

What is the correct syntax for a lambda expression with no parameters that returns a fixed value?

Q.89Easy

Given: Function<Integer, Integer> f = x -> x * 2; Integer result = f.apply(5); What is the value of result?

Q.90Medium

Which stream operation uses a lambda expression to transform elements from one type to another?

Q.91Hard

Consider a scenario where you need to sort a list of strings by length. Which lambda expression is most appropriate for Comparator?

Q.92Hard

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

Q.93Hard

In the context of exception handling with lambda expressions, what happens if a lambda body throws a checked exception?

Q.94Hard

Which of the following best demonstrates the use of Optional with lambda expressions for safe null handling?

Q.95Easy

Which functional interface is used to create a lambda expression that takes two integers and returns a boolean value?

Q.96Easy

What will be the output of the following code? List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5); numbers.stream().filter(n -> n % 2 == 0).forEach(System.out::println);

Q.97Medium

Which of the following lambda expressions is INVALID in Java?

Q.98Medium

A stream processes a list of strings and applies a lambda to convert them to uppercase. Which intermediate operation should be used?

Q.99Medium

Consider the following code: List<String> fruits = Arrays.asList("apple", "banana", "cherry"); fruits.removeIf(s -> s.length() > 5); What will be the contents of 'fruits' list after execution?

Q.100Hard

What is the return type of a lambda expression used with IntStream.range(1, 5).map(x -> x * 2)?