iGET

Java Programming - MCQ Practice Questions

Practice free Java Programming multiple-choice questions with detailed answers and explanations. Perfect for competitive exam preparation.

951 questions | 100% Free

Q.801Medium

Which functional interface should be used for a lambda that filters elements?

Q.802Medium

What will this code print? List<Integer> list = Arrays.asList(1, 2, 3, 4, 5); list.forEach(x -> System.out.print(x + " "));

Q.803Medium

Can lambda expressions access local variables from their enclosing scope?

Q.804Medium

Which of the following correctly represents a BiFunction?

Q.805Medium

What is the difference between a lambda expression and an anonymous inner class?

Q.806Hard

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));

Q.807Medium

Which of the following statements about @FunctionalInterface is true?

Q.808Easy

What is the output of this code? Consumer<String> print = s -> System.out.println(s.toUpperCase()); print.accept("java");

Q.809Medium

Can a lambda expression have multiple statements in its body?

Q.810Medium

Which functional interface is best suited for this scenario: method that takes no parameters and returns a random number?

Q.811Hard

What will happen if you try to compile this code? BiFunction<String, String, String> concat = (a, b) -> a + b; concat.apply("Java", "8", "Features");

Q.812Medium

In Java streams, what does the filter() method use?

Q.813Hard

What is the type inference mechanism in lambda expressions?

Q.814Easy

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

Q.815Easy

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

Q.816Easy

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

Q.817Easy

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

Q.818Medium

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

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

Q.820Medium

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