In this example you will see what are Predicate and Function functional interfaces in Java 8 or later version of Java. Functional interfaces provide target types for lambda expressions and method references. Each functional interface has a single abstract method, called functional method for that functional interface, to which the lambda expression’s parameter and return…

Posted in Java

Predicate and Function functional interfaces in Java 8 or later

Parallel Stream Vs CompletableFuture I am going to discuss here CompletableFuture vs Parallel Stream in Java programming language. CompletableFuture extends Future with added advantage to allow the tasks finish in an ad hoc manner, whereas, in Parallel Stream task is divided into sub-tasks and run on separate threads to be completed faster. Both CompletableFuture and…

Posted in Java

Difference Between Parallel Stream And CompletableFuture In Java

In this example I am going to show you how to check if an input date is past date or today’s date or future date. I am using Java version 12 and for this example you should use at least Java version 8. Java 8 or higher version provides thread safe version of date time…

Posted in Java

Check a Given Date is Past, Today or Future’s Date in Java 8

I am going to show you how to work with parallel stream in Java 8 or higher version of Java. In parallel computing a task is divided into sub-tasks and these sub-tasks are computed parallelly in each separate threads and finally the result of the solution for each sub-tasks is combined. One of the features…

Posted in Java

Parallelism Example in Java Stream API

Java 8 Date In this tutorial I am going to show you how to add days, weeks, months, years to a particular date in Java 8 or later. Similarly I will also show how to substract days, weeks, months, years from a particular date. The date is actually LocalDate API in Java 8 or later….

Posted in Java

Add Or Subtract Days Weeks Months Years On Java 8 Date

Introduction In this tutorial we will see an example on how to find unique strings or objects using Java stream API. Stream API was introduced in Java 8 and we are going to see how to use this stream API to remove duplicates from strings or objects. Java stream API has a method distinct() that…

Posted in Java

How to find unique strings or objects using Java stream API

Introduction I will discuss here about the new feature added to Java 8 – a functional interface, Supplier, Consumer and BiConsumer. In simple words, a supplier is a method that returns a value. A supplier is any method which takes no arguments and returns a value. Its job is to supply an instance of an…

Posted in Java

Supplier, Consumer and BiConsumer in Java 8

Map To List Objects Here I will show you how to convert List of Map objects into List of objects using Java 8’s or later’s Stream API. The List of Map objects can be found as a result of selecting multiple records from database table or any other sources. Then you may need to convert…

Posted in Java

Convert List of Map Objects Into List Of Objects Using Java Stream

Introduction This example shows you how to convert milliseconds into years, months, weeks, days, hours, minutes, seconds in Java. Sometimes we need to convert the milliseconds into years or months or weeks or days or hours or minutes or seconds. For example, when you want to check the exact time taken by a program to…

Posted in Java

Convert Milliseconds into Years, Months, Weeks, Days, Hours, Minutes, Seconds in Java

Introduction This example shows you hot to convert milliseconds into days, hours, minutes, seconds in Java. Sometimes you need to convert the milliseconds into days or hours or minutes or seconds. Typically when you want to check the exact time taken to execute a program then you may need to calculate the time. So in…

Posted in Java

Convert Milliseconds into Days, Hours, Minutes, Seconds in Java

Introduction In this tutorial I am going to show how default and static methods can be included into Java 8 interfaces. Prior to Java 8 you did not have such mechanism to include default method or static method into interface but Java 8 provides such option to include those methods. Prior to Java 8 if…

Posted in Java

Java 8 onward Default and Static Methods Example

Introduction In this tutorial I am going to show how to create custom thread pool in Java. Multi-threaded and multi-process programmings are great ways to optimize CPU usage and get things done quickly. What is thread pool? Thread pool is a collection of already created worker threads ready to perform certain tasks. Instead of creating…

Posted in Java

How to create Custom Thread Pool in Java