Thursday, 18 May 2017

Java Tutorial: Lambda expression in java[Thread creation using Lambda expression]


Click here to watch in Youtube :
https://www.youtube.com/watch?v=4qHFrzYJ1XU&list=UUhwKlOVR041tngjerWxVccw

LambdaDemo.java
/**
 * With JDK 8
 * 
 * Java Lambda Expression Example: Creating Thread
 *
 */
public class LambdaDemo
{

    public static void main(String[] args)
    {
        /*
         * Thread Example with lambda.
         * 
         * we are implementing run method by using lambda expression.
         */

        Runnable runnable = () -> {
            System.out.println("Thread is running...");
        };
        Thread thread = new Thread(runnable);
        thread.start();
    }

}
Output
Thread is running...
NonLambdaDemo.java
/**
 * Before JDK 8
 *
 */
public class NonLambdaDemo
{

    public static void main(String[] args)
    {
        // Thread Example without lambda
        Runnable runnable = new Runnable()
        {
            @Override
            public void run()
            {
                System.out.println("Thread is running...");
            }
        };
        Thread thread = new Thread(runnable);
        thread.start();
    }

}

Output
Thread is running...
Click the below link to download the code:
https://sites.google.com/site/ramj2eev1/home/javabasics/LambdaDemo_thread_create_App.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/LambdaDemo_thread_create_App

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/539015917c8406e4be671410d713073b3971d1a5/BasicJava/LambdaDemo_thread_create_App/?at=master

See also:

  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial
  • 1 comment:

    1. It's interesting that many of the bloggers to helped clarify a few things for me as well as giving.Most of ideas can be nice content.The people to give them a good shake to get your point and across the command.
      Java Training in Chennai

      ReplyDelete

    Google+ Followers

    Google+ Badge