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

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

Q.22Easy

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

Q.23Easy

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

Q.24Easy

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

Q.25Medium

What will be the result of executing: List<Integer> nums = Arrays.asList(1, 2, 3, 4); nums.stream().map(x -> x * 2).collect(Collectors.toList());

Q.26Medium

Consider: Function<Integer, Integer> f = x -> x * x; What will f.apply(5) return?

Q.27Medium

What is the purpose of the Optional class when used with lambda expressions in Stream operations?

Q.28Medium

Which of the following lambda expressions is INCORRECT?

Q.29Medium

Consider: Stream.of(1, 2, 3, 4, 5).filter(x -> x > 2).map(x -> x * x). What will the terminal operation need to be?

Q.30Medium

What is method reference (::) in Java and how does it relate to lambda expressions?

Q.31Medium

What is the difference between peek() and forEach() when used with lambda expressions in Streams?

Q.32Medium

In the lambda expression (a, b) -> a.compareTo(b), what is the implicit functional interface?

Q.33Medium

What will be the output of: IntStream.range(1, 4).map(x -> x * 2).sum();

Q.34Hard

Consider a lambda that needs to throw a checked exception. Which approach is correct?

Q.35Hard

What is the time complexity of reducing a stream with a lambda expression using reduce()?

Q.36Hard

Consider: List<String> list = Arrays.asList("a", "b", "c"); list.stream().collect(Collectors.toMap(s -> s, s -> s.length())). What type is returned?

Q.37Hard

What issue can arise when using lambda expressions with flatMap() in nested streams?

Q.38Hard

Consider: Function<Integer, Function<Integer, Integer>> curry = x -> y -> x + y; What does curry.apply(5).apply(3) return?

Q.39Easy

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

Q.40Easy

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