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
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 23, 2018

How to use or implement test and negate methods in java.util.function.BiPredicate in java

We have Functional Interfaces in java, which returns a boolean-value after operating on it’s inputs. BiPredicate is one of those Functional interfaces, which returns a boolean value. It has four functions in it’s definition. Three of them are default and one is abstract and it is called test. boolean test( T input1, U input2) :- It returns a […]

Read more
December 17, 2018

Using java.util.function.BinaryOperator to create function to return maximum and minimum value in functional programming way

You can read first part of this article here . We all have implemented methods to get maximum or minimum between two different values. A value can be anything, it can be a primitive or an object. It can be an integer or a string or a person object. We were doing this in an […]

Read more
November 28, 2018

What is lambdas in Java – Understanding Lamdas in Java

Lambdas were introduced in Java 8. For me they are first step towards functional programming in java. Lambdas are a little like anonymous class. They are similar in the way they are defined and passed around as a parameter in functions. But, lambdas are not exactly an anonymous class. After compilation, an anonymous class has […]

Read more
November 22, 2018

How to cache hashcodes in an immutable class.

We can keep a member variable to store hashcode for the created object. And we will return that variable whenever, a user asks for hashcodes. Here, in this article, we will use a class which is an immutable class. In the below class, I use hashcode instance variable to store the hashcode. Hashcode for a given object […]

Read more
November 22, 2018

Why an Immutable class is declared final

If you read my article – How to create an immutable class – I have mentioned there,  to use final keyword to make your class immutable. But.. Why? An immutable class has only one version on all the system. Like  String class in Java. You can not create another version of it. The Behaviour of String  class is consistent on all […]

Read more
November 18, 2018

Using java streams to create immutable class

In my post – How to create immutable classes – to make lists immutable, I created a new List-Object everytime. This is the class which, we are going to modify in this tutorial. package immutable; import java.util.ArrayList; import java.util.Date; import java.util.List; final public class Person { private int age; private String name; private Date dateOfBirth; private […]

Read more
November 14, 2018

How to create a Java class, whose objects or instances are immutables

This is one of the most common interview questions. If you have more than two years of professional experience in java development, then you are going to face this question. In this article, I will show you, how to create a class, which creates an immutable objects or instances. First of all, what does immutable […]

Read more