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

Which of the following lambda expressions is invalid?

Q.2Medium

What is the type of the following lambda expression: x -> x.length()?

Q.3Medium

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

Q.4Medium

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

Q.5Medium

Can lambda expressions access local variables from their enclosing scope?

Q.6Medium

Which of the following correctly represents a BiFunction?

Q.7Medium

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

Q.8Medium

Which of the following statements about @FunctionalInterface is true?

Q.9Medium

Can a lambda expression have multiple statements in its body?

Q.10Medium

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

Q.11Medium

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

Q.12Medium

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

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

Q.14Medium

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

Q.15Medium

Which of the following lambda expressions is INCORRECT?

Q.16Medium

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

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

Q.18Medium

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

Q.19Medium

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

Q.20Medium

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