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
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
January 21, 2019

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

Read more
January 19, 2019

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

Read more
January 18, 2019

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

Read more
January 11, 2019

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

Read more
January 7, 2019

Implementing java.util.function.DoubleBinaryOperator in java – functional programming.

DoubleBinaryOperator is a Functional Interface . It has only one abstract method and has no default method, unlike many other functional interfaces. It is a primitive type specialization of BinaryOperator. If we are trying to implement BinaryOperator for a double type, rather than doing that, we can use DoubleBinaryOperator for that. It has only one function. […]

Read more
December 25, 2018

Creating a boolean switch using BooleanSupplier, which alternatively returns true and false.

In this article, we will create a BooleanSupplier implementation, which returns true or false value on the alternate basis. If it returns true on current call, then it will return a false on the next call and a true on the next to next call, and this will go on. This is a very simple […]

Read more
December 25, 2018

Providing implementation for getAsBoolean in BooleanSupplier – a functional interface – in java

If you don’t know about Functional Inteface then you can read about it, in the provided link. Now coming to BooleanSupplier, it is a functional interface. It has only one abstract method. boolean getAsBoolean() :- it returns a boolean value and has no input parameters. It can be used to provide streams of boolean values. Implementation 1 […]

Read more
December 24, 2018

How to use default methods and and or, to compose new BiPredicate implementations from other BiPredicates in java

In BiPredicate Part 1 , we learnt about using test and negate functions. In this article we will use default methods and and or methods to compose BiPredicates, which can perform all the tests of composing BiPredicates. Our use case is to create a system, which helps HR personnel to identify potential candidates for hiring. We will check for three […]

Read more