Skip to main content

Posts

Showing posts from February, 2023

JAVA 8 Features

 Overview of Java 8 Features Some of the important Java 8 features are; 1) forEach() method in Iterable interface 2) default and static methods in Interfaces 3) Functional Interfaces and Lambda Expressions 4) Java Stream API for Bulk Data Operations on Collections 5) Java Time API 6) Collection API improvements 7) Concurrency API improvements 8) Java IO improvements Now we discuss step by step these features 1. forEach() method in Iterable interface Whenever we need to traverse through a Collection, we need to create an Iterator whose whole purpose is to iterate over, and then we have business logic in a loop for each of the elements in the Collection. We might get ConcurrentModificationException if the iterator is not used properly. Java 8 has introduced forEach method in java.lang.Iterable interface so that while writing code we focus on business logic. The forEach method takes java.util.function.Consumer object as an argument, so it helps in having our business logic at a separa...