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 […]
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, […]
using Anonymous class to extend thread class
In this article, I wrote about extending a Thread class to create a Thread in java. We can also use anonymous class to create a Thread. So, this article will cover the part, where we use anonymous class to provide the thread implementation. If you don’t know, when we declare an anonymous class, it is […]
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 […]
Using lambda and Functional Programming to provide implementation for Callable interface – which prints a string n number of times in java
Callable is a Functional interface, it is similar in usage to Runnable interface. But with a small difference, that Callable can return a value, while Runnable can not return a value. In this tutorial, we will create a Callable which will return a String output. The string output is going to return String Value, which will be contain a given word repeated n number of times. Given Values :- […]