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

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

Q.822Easy

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

Q.823Easy

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

Q.824Easy

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

Q.825Medium

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

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

Q.827Medium

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

Q.828Medium

Which of the following lambda expressions is INCORRECT?

Q.829Medium

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

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

Q.831Medium

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

Q.832Medium

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

Q.833Medium

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

Q.834Hard

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

Q.835Hard

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

Q.836Hard

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

Q.837Hard

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

Q.838Hard

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

Q.839Easy

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

Q.840Easy

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