Java 8 – New Features

1. Overview

In this article, we’ll have a quick look at some of the most interesting new features in Java 8.

2. Default and Static Methods

2.1 Default Method

Default methods are declared using the new default keyword. These are accessible through the instance of the implementing class and can be overridden.

Let’s add a default method to our Employee interface.

default String getAddress() {
    return "This is default address";

Assume that this interface is implemented by the class EmployeeImpl. For executing the default method an instance of this class should be created:

Employee emp = new EmployeeImpl();
String overview = emp.getAddress();

2.2 Static Method

Consider the following method of the interface (let’s call this interface Employee):

static String address() {
    return "XYZ";

The static order() method is available only through and inside of an interface. It can’t be overridden by an implementing class.

To call it outside the interface the standard approach for static method call should be used:

String address = Employee.address();

3. Method References

3.1 Reference to a Static Method

3.2 Reference to an Instance Method

3.3 Reference to an Instance Method of an Object of a Particular Type

3.4 Reference to a Constructor

4. Optional

4.1 Creation of the Optional

4.2 Optional Usage

5. Functional Interface

6. Lambda Expressions

7. Stream API

8. Date API

Author: Mahesh

Technical Lead with 10 plus years of experience in developing web applications using Java/J2EE and web technologies. Strong in design and integration problem solving skills. Ability to learn, unlearn and relearn with strong written and verbal communications.