February 17, 2019

Using anonymous class to implement runnable interface in java

You can read about the other ways for implementing runnable interface – using a java class, and using lambda. In this part, we will use anonymous class for doing this. In my opinion, at the time of writing this article, the anonymous class is pretty useless now. If you need an anonymus class then use […]

Read more
February 10, 2019

Using java lambda to provide implementation for Runnable interface.

There are many ways to create a thread. One of those ways is implementin Runnable interface. Again there are several ways to provide an implementation for it. One of those ways is, using lambda to provide an implementation. If you don’t know anything about lambda, then you can read it here. You are gonna need […]

Read more
February 3, 2019

Implement runnable interface using a class in java.

Runnable is a Functional Interface. It has one abstract method called run. To make use of this class, we need to provide an implementation for this method. In practice, compiler only needs a non-abstract method. You can provide a empty body and that will be enough. The implementation need not be meaningful. Here is a simple class, […]

Read more
January 29, 2019

Extending Thread Class to create threads in java.

To create Thread, we basically need to provide an implementation for run function. We can do it in two ways. Either we can extend Thread class and override it’s run method or we can implement Runnable interface and provide an implementation for it’s abstract run method. In this article, I am extending Thread class. public class SimpleThread extends Thread { } We have […]

Read more
December 4, 2018

Simple implementation for Callable interface in Java, using lambda.

In this tutorial, we will learn basic implementations for Callable interface  using lambda in java. Anonymous Class providing an implementation for Callable interface. Callable<String> callMyName = new Callable<String>() { @Override public String call() throws Exception { return “Anurag Anand”; } }; You can submit the above implementation to return any string value. The same can be […]

Read more
November 30, 2018

Using java lambda to create threads using runnable interface in java

I am using jdk-11 for this tutorial. We are going to use lambda functions to create a thread in java. In this tutorial, we will implement Runnable  interface. Our lambda implementation will print numbers from the range 1 to 10. Step 1 :- implement Runnable interface Runnable runThroughLambda = () -> IntStream.rangeClosed(1, 10) .forEach(System.out::println); In above code, I […]

Read more