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
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));
What will happen if you try to compile this code? BiFunction<String, String, String> concat = (a, b) -> a + b; concat.apply("Java", "8", "Features");
What is the type inference mechanism in lambda expressions?
Consider a lambda that needs to throw a checked exception. Which approach is correct?
What is the time complexity of reducing a stream with a lambda expression using reduce()?
Consider: List<String> list = Arrays.asList("a", "b", "c"); list.stream().collect(Collectors.toMap(s -> s, s -> s.length())). What type is returned?
What issue can arise when using lambda expressions with flatMap() in nested streams?
Consider: Function<Integer, Function<Integer, Integer>> curry = x -> y -> x + y; What does curry.apply(5).apply(3) return?
What is the time complexity of reducing a stream with a stateful lambda operation?
Consider: Function<Integer, Function<Integer, Integer>> curried = a -> b -> a + b; What is this pattern called?
Consider: Stream.of(1, 2, 3).map(x -> { System.out.println(x); return x * 2; }).collect(Collectors.toList()); What will print?
What is the correct way to chain lambda expressions using Function interface? Function<Integer, Integer> f1 = x -> x * 2; Function<Integer, Integer> f2 = x -> x + 5; How to apply f1 first, then f2?
Consider a scenario where you need to sort a list of strings by length. Which lambda expression is most appropriate for Comparator?
What is the difference between a lambda expression and an anonymous inner class in Java?
In the context of exception handling with lambda expressions, what happens if a lambda body throws a checked exception?
Which of the following best demonstrates the use of Optional with lambda expressions for safe null handling?
What is the return type of a lambda expression used with IntStream.range(1, 5).map(x -> x * 2)?