In this blog, I will show you the different ways to implement java.util.function.Function interface in modern java. You can watch me code these examples on youtube. First implementation is using implementation keyword in a regular class private class FuncImpl implements Function<Person, Integer>{ @Override public Integer apply(final Person person){ return person.getAge(); } } Second way uses anonymous class for implementation. […]
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 […]
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 […]
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 […]
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 […]
Create a complete binary tree from an array of data in java
Note :- Using java 8 and above. Hi there… Today, I am going to write a java program which will take an var-arg of character, you can use any data-type you want. Data type is not the focus here. The main focus is the process of creating a binary tree. I am using functional programming to do […]
How to implement java.util.function.DoubleToIntFunction in java
java.util.function.DoubleToIntFunction is a Functional Interface. It has only one method, and that is an abstract method. This abstract method is declared to accept one double value as an input-parameter, and it returns an int value. Both, input and output are primitives. These classes are specialized versions for primitive. As JVM doesn’t need to do boxing and unboxing. […]
Implement java.util.function.DoubleSupplier to return random numbers – java 11 and above
java.util.function.DoubleFunction is a Functional Interface. It has one abstract method, which takes no input but returns a double value. It can be used as a supplier of double values, and it can be used to create a doublestream double getAsDouble() :- it returns a double value, that’s all it’s declaration says. In this article, we will write an […]
How to Implement java.util.function.DoublePredicate’s function – test, and, or and negate in java
This code should run in java 11 and above. It definitely needs – above java 8. Few things will work in java 9 or 10. But, code should successfully run in java 11 and above. Because, I am running java 11. So, In this episode of java wonderland, we are going to implement java.util.function.BinaryPredicate. Those who […]
Implementing java.util.function.DoubleConsumer in java, and using random numbers to test it.
Java provides a lot of Functional Interface , some are generic , can be used by all the data-types, whereas some are specialised for primitive types. Reasons, that I can think of are, they are a providing interfaces, which are going to be used most often second, they are providing some compiler magic to optimize these interfaces. […]