Java 8

Java 8 : BiConsumer Functional Interface

java.util.function.BiConsumer BiConsumer is similar to a Consumer. It accepts two input parameters, but doesn’t return anything. @FunctionalInterface public class BiConsumer<T, U> {     void accept(T t, U u); // Performs this operation on the given argument.     default BiConsumer<T,U> andThen(BiConsumer<? super T,? super U> after) }   Example 1 : BiConsumer package com.topjavatutorial; import java.util.function.BiConsumer; public class […]

Java 8

Java 8 : java.util.function.Consumer Functional Interface

This article describes Java 8 Consumer Functional Interface with examples. What is a Consumer ? Consumer is a functional interface added in Java 8 that has a single abstract method accept(). A Consumer is used when you want to perform an operation that takes a parameter but doesn’t return anything. Here is how the Consumer […]

Java 8

Java 8 : java.util.function.Supplier Functional Interface

In this article, we will see what is Supplier Functional Interface introduced in Java 8 using examples. What is java.util.function.Supplier ? Supplier is a functional interface with a single abstract method get(). This was introduced in Java 8. @FunctionalInterface public class Supplier<T> {     public T get();      }   When to use a Supplier Functional […]

Java 8

How to find date time differences in Java 8

In Java8, we can use following classes to find date time differences : Period Duration ChronoUnit   Period We can use Period class to calculate difference in year, month, days between two Dates. Here is an example of using Period class methods getYears(), getMonths() and getDays() to calculate age of a person. package com.topjavatutorial; import […]

Java 8 Interview Questions – Part 2

In this article, we will discuss frequently asked Java 8 Interview Questions and Answers. You can refer the Part 1 using this link : Java8 Interview Questions : Part 1   Java 8 Interview questions 1. What are Static Interface Methods in Java 8 ? How are static Interface methods invoked ? JDK 8 added […]