by BehindJava

WAP to create a thread using lambda expression and print “Hello” in Java

Home » java » WAP to create a thread using lambda expression and print “Hello” in Java

WAP to create a thread using lambda expression and print “Hello”?

In this tutorial, we are going to learn how “hello” is printed by creating a thread using lambda expression. Java provides an annotation @FunctionalInterface, which is used to declare an interface as functional interface.

It is not mandatory to use this annotation, an interface with single abstract method is by default considered as functional interface.

Lambda expression provides implementation of functional interface. An interface which has only one abstract method is called functional interface.

Sample Code Snippet:

public class ThreadCheck {
	public static void main(String[] args)
	{
        // providing implementation for runnnable interface which 
        // has single abstract method i.e. run()		Runnable r=()-> {
			 {
				System.out.println("Hello");
			 }	
		     };
		Thread t1=new Thread(r);		t1.start();
	}