November 21, 2020

Use IntUnaryOperator to calculate sum and cube of an int using modern java : java functional programming

There are different ways to implement IntUnaryOperator . You can watch my video, where I am implementing IntUnaryOperator. Utility Class with square and cube static functions. private static class Utility{ private static final int square(final int intValue) { return (int) intValue * intValue; } private static final int cube(final int intValue) { return (int) intValue * […]

Read more
October 28, 2020

java.util.function.IntFunction implementation using modern java

IntFunction is a functional interface, it takes an int and returns a reference type. This reference type can be specified by using generic type specification. We can implement it in different ways. Implement using a regular class. private class IntFuncImpl implements IntFunction<Integer>{ @Override public Integer apply(final int intValue) { return Integer.valueOf(intValue); } } Implement using […]

Read more
October 28, 2020

Double Unary Operator Implementation using modern java

DoubleUnaryOperator is a functional interface that lives in java.util.function package. It has one function applyAsDouble, which takes a double and returns a double. It is called an UnaryOperator, because it performs it’s action on a single argument. And, that single argument is of double type that’s why it has Double in it’s name. We can implement […]

Read more
October 10, 2020

java.util.function.IntConsumer implementation using modern Java

In this post, I will show you different ways to implement java.util.function.IntConsumer functional interface. You can watch me coding all of these implementation on youtube. First one is a class implementation, where we use implements keyword to provide an implementation, we have been doing this since the start of Java. class IntCons implements IntConsumer{ @Override public void accept(final int […]

Read more
October 10, 2020

java.util.function.IntBinaryOperator implementation in modern Java

In this blog post, I will show you the different ways to implement java.util.function.IntBinaryOperator. You can watch my youtube video, where I code these implementation. A Regular Class.. private class RegularImpl implements IntBinaryOperator{ @Override public int applyAsInt(final int firstIntValue, final int secondIntValue){ return firstIntValue > secondIntValue ? firstIntValue : secondIntValue; } } Implementation using a […]

Read more
September 11, 2020

Sum Of Integer Array : How To Do Functional Programming In Java

We can use functional Programming in Java to calculate sum of an int array. You can watch my live coding video to see how it is done. Traditional Way :- int sum = 0; for(int intValue : ints) sum += intValue; Functional Programming Way 1 :- Arrays.stream(ints).sum(); Functional Programming Way 2 :- Arrays.stream(ints).reduce(0, Integer::sum); Functional […]

Read more
September 11, 2020

Currying : How To Do functional Programming In Java

One of the key identifiers of functional programming is Currying. Since Java 8, the new features were added, allows us to do this operation. What is currying? currying is a name assigned to ‘half initialized functions’. A Curried function has some of the parameters fixed while other parameters will be passed by the users. We […]

Read more
February 10, 2019

How to implement java.util.function.DoubleToLongFunction

java.util.function.DoubleToLongFunction is a primitive specialization of Other Functional Interfaces. What it means is , we can get the same functionality using other functional interfaces, but they are going to be slow. Because of boxing and unboxing. If you are dealing with Double and Long wrapper objects then use other functional interface. So, this functional interface is […]

Read more
January 26, 2019

What are effective final variables in java, and where we can use it.

There is a final keyword, which is used to make a reference value permanent. It means – the value can not be changed once defined. Then there is effective final variable. These variables are not declared final. But, depending on the context they can be considered as final. What do i mean from a context? you should […]

Read more