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

Consider: Stream.of(1, 2, 3, 4, 5).filter(x -> x > 2).map(x -> x * 2).forEach(System.out::println); What will be the output?

Q.22Medium

What is the difference between peek() and forEach() in streams?

Q.23Medium

What issue can arise when using lambda expressions with checked exceptions?

Q.24Medium

What will be the output of: IntStream.range(1, 4).map(x -> x * x).forEach(System.out::print);

Q.25Medium

In the lambda expression (a, b) -> a.compareTo(b), what can we infer about the parameters?

Q.26Medium

Which of the following correctly uses method reference with constructor?

Q.27Medium

What happens when a lambda expression references a local variable from its enclosing scope?

Q.28Medium

What will be the output of: List<Integer> list = Arrays.asList(1, 2, 3); list.replaceAll(x -> x * 2); System.out.println(list);

Q.29Medium

Which of the following lambda expressions has incorrect syntax?

Q.30Medium

What will be the type of the lambda expression (x) -> x.toString()?

Q.31Medium

Which functional interface should be used for a lambda with no parameters and no return value?

Q.32Medium

What is the difference between Consumer and Function functional interfaces?

Q.33Medium

Which of the following uses method reference correctly?

Q.34Medium

Which of the following lambda expressions will compile successfully?

Q.35Medium

In the lambda expression (x) -> x < 10 && x > 0, what is the parameter type?

Q.36Medium

Which of the following statements about variable scope in lambda expressions is TRUE?

Q.37Medium

Consider: Comparator<String> comp = (s1, s2) -> s2.compareTo(s1); What does this lambda expression do?

Q.38Medium

Which lambda expression is equivalent to the method reference Integer::parseInt?

Q.39Medium

Analyze: What is the output? BiConsumer<String, String> printer = (a, b) -> System.out.println(a + b); printer.accept("Java", "8");

Q.40Medium

What is the return type of a lambda expression (x, y) -> x + y where x and y are integers?