December 13, 2018

Learn how to implement java.util.function.BiFunction in java.

I am using java 11, you will need to modify the codes a bit to work in java below version 11. BiFunction is a Functional Interface , It has two methods in it, andThen  and apply. The method andThen  has a default implementation and apply  method is an abstract. andThen :- This method is used to chain multiple BiFunction together. It helps to execute […]

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 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 :- […]

Read more
November 24, 2018

Create a simple counter in java 11, using java IntSupplier – Then test it using IntStream – a functional programming way.

We will create a simple counter in java. It will have a default initialization of 0. It will have a constructor, which can be used to set the seed value of this counter. It will implement Iterator interface It will implement IntSupplier interface package com.refactored.util; import java.util.Iterator; import java.util.function.IntSupplier; public class Counter implements Iterator<Integer>, IntSupplier […]

Read more