Java Lambda Expressions Interview Questions

    Question 1JAVA - Lambda Basics

    What is the main purpose of lambda expressions in Java?

    Question 2JAVA - Lambda Syntax

    Which is the correct syntax for a lambda expression that takes two integers a and b and returns their sum?

    Question 3JAVA - Functional Interface

    Which annotation is used to mark a functional interface in Java?

    Question 4JAVA - Lambda Example

    What will this code print?

    interface Say { void speak(String msg); } public class Test { public static void main(String[] args) { Say s = (msg) -> System.out.println("Hello " + msg); s.speak("Java"); } }

    Question 5JAVA - Lambda with Thread

    What will happen?

    public class Test { public static void main(String[] args) { Thread t = new Thread(() -> System.out.println("Thread running")); t.start(); } }

    Question 6JAVA - ForEach with Lambda

    What will this code print?

    import java.util.*; public class Test { public static void main(String[] args) { List<String> list = Arrays.asList("A", "B", "C"); list.forEach(s -> System.out.print(s + " ")); } }

    Question 7JAVA - Method Reference

    Which is a valid method reference in Java?

    Question 8JAVA - Scope in Lambda

    Which statement about lambda expressions is true?

    Question 9JAVA - Stream with Lambda

    What will this code print?

    import java.util.*; public class Test { public static void main(String[] args) { List<Integer> nums = Arrays.asList(1, 2, 3, 4); nums.stream().filter(n -> n % 2 == 0).forEach(System.out::print); } }

    Question 10JAVA - Comparator with Lambda

    Which lambda correctly sorts a list of strings by length?