Java 8 onward Default and Static Methods Example

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 a new methods was added…

How to create Custom Thread Pool in Java

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 and discarding thread once the…

Java 8 : Iterate Map And Add To List

Here I will show you how to iterate Map in Java 8 and add element to List. I came across a situation where I required to fetch data from a HashMap and add it to an ArrayList. So I will show you here how to iterate a Map and form an object and finally add it to the List using…

Collect and Convert Objects using Lambda Expression in Java 8 or Later Version

Introduction In this tutorial, I will show you how you are going to collect and convert objects using lambda expression in Java 8 stream API. I will collect objects and map to another custom objects using Java 8 stream API with the help of Lambda Expression. Suppose you have entity classes generated from your database tables and after fetching data…

Java 8 Stream Filter Example

Java 8 Filter This tutorial will show you how to use Java 8 stream API‘s filter() and map() methods. The filter() method in Java 8 or onward is used to produce a stream containing only a certain type of objects into the result output and map() method is used to transform a stream from one type to another type into…

CompletableFuture in Java 8 or later

Introduction Here I will discuss about Java 8 or later version’s new feature CompletableFuture in Java programming language. Using Java 8 or later version’s CompletableFuture API you can complete the tasks in an ad hoc manner. A Future represents the pending result of an asynchronous computation. It offers a method — get() — that returns the result of the computation…

Java 8 Date and Time API

Introduction Here I am going to discuss about the Java 8 or later version’s new date and time API. The date time package, java.time, was introduced in the Java SE 8 release, which provides a comprehensive model for date and time. The new date and time API offers greatly improved safety and functionalities for developers.

Java 8 Stream API

Introduction In this tutorial I will explain about Java’s new API called stream, which was introduced in Java 8 and included in package java.util.stream. The stream API supports functional-style operations on collection of elements or stream of elements in a collection.

Java forEach Example Using Lambda Expression

Introduction This tutorial will show you how to use Java 8 forEach() loop to iterate Collection using Lambda Expression. Prior to Java 8 or JDK 8, the for loop was used as a for-each style but in Java 8 the inclusion of forEach() loop simplifies the iteration process in mainly one line.