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
In Java 8, a lambda expression can access local variables from its enclosing scope. What is the constraint on these variables?
What is the return type of the map() method when used with lambda expressions in Java Streams?
Consider the code: List<String> names = Arrays.asList("Raj", "Priya", "Amit"); names.forEach(n -> System.out.println(n)); What does this code do?
Which functional interface is used for operations that take no arguments and return a value?
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());
Consider: Function<Integer, Integer> f = x -> x * x; What will f.apply(5) return?
What is the purpose of the Optional class when used with lambda expressions in Stream operations?
Which of the following lambda expressions is INCORRECT?
Consider: Stream.of(1, 2, 3, 4, 5).filter(x -> x > 2).map(x -> x * x). What will the terminal operation need to be?
What is method reference (::) in Java and how does it relate to lambda expressions?
What is the difference between peek() and forEach() when used with lambda expressions in Streams?
In the lambda expression (a, b) -> a.compareTo(b), what is the implicit functional interface?
What will be the output of: IntStream.range(1, 4).map(x -> x * 2).sum();
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 primary advantage of using lambda expressions in Java 8+?
What will be the output of: List<String> list = Arrays.asList("a", "bb", "ccc"); list.forEach(s -> System.out.print(s.length() + " "));