Java 8 tutorial

Welcome to Java 8 tutorial. Here we will guide you step by step through all the new language features of Java 8. To use all features of Java 8 you need to download JDK 8. Java 8 is the most awaited and is a major feature release of the Java programming language. Here we list down all the important features of Java 8. We will discuss all the features of Java 8 in a separate post and cover them by use of real-time examples.

Features of Java 8 tutorial

1. Functional Interface

An interface that can contain only one abstract method/function is known as a functional interface. The term Java functional interface was introduced in Java 8. From Java 8 onwards, you can ensure that your interface is functional or not. To ensure the functional interface you should add the annotation @FunctionalInterface. Runnable and Comparable are the most common examples of functional interfaces. You can check their source code. These interfaces are also called Single Abstract Method interfaces (SAM Interfaces). In java, there are some existing interfaces Runnable, Comparable. For more detail.

2. Lambda expressions

Lambda expressions are new features for JAVA, but it is already existing in Some other popular programming languages like Scala.
Java 8 onwards supports functional programming. Because now you can pass a function as a parameter in another function. It is an anonymous function(A function without a name). Java has been lacking this from the beginning. Let’s discuss it in detail.

3. Method references

The method references are the shortened notation of lambda expressions to call a specific method. It helps to refer to methods by their names. Method reference is used to refer method of functional interface

As you already know lambda expression reduces the code as compared to the anonymous class. The method reference is the next step of the lambda expression. Like lambda expression, the Method reference executes only a single method. Let’s discuss it in detail.

4. forEach() method

The forEach() method works as a utility method that helps to iterate over a collection or stream. The forEach() method accepts the reference of Consumer Interface and performs a certain action on each element of it which define in Consumer. Let’s discuss it in detail.

5. Default method

Till Java 7, the Interface could have only abstract methods. We have learned a lot of things about interfaces. As we already know a separate class is used to provide the implementation of abstract methods. If the programmer adds a new method to an interface, then the implementation of a new abstract method must be provided by the class which is implementing the interface. To resolve the issue, Java 8 introduced default methods and static methods in interfaces. We will discuss it in detail.

6. Streams

A Stream in Java is a sequence of objects that provide various method that helps to produce the desired result.  The Stream takes data from a source that supports aggregate operations on them. Collections and Arrays are the sources of Stream. It presents in Let’s discuss it in detail.

7. Date and time java 8 API

Before java, there is some problems with the Date and time class. Java 8, introduced some new classes to handle the data and time. These new classes come along with the date and time API. Let’s discuss it in detail.

Java 8 tutorial

4 thoughts on “Java 8 tutorial”

Leave a Comment