Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / Java

What Are the Most Important New Features in the Java 8 Release?

5.00/5 (2 votes)
13 Jan 2015CPOL1 min read 13K  
This tip shows you the most important new feature in Java 8 release.

Introduction

Oracle has made a great move by delivering several new features in Java to let developers create a clean, concise and an effective code and be much more productive. This release didn't touch only Java as language but also its libraries, compile and even the Java Virtual Machine. That is why experts all over the world think that this release is the biggest Java revolution since the fifth release in 2004.

Background

So, there are several new features like the lambdas expression, the newly Stream API, the concurrency, the parallel arrays, the Date/Time API and others.

Personally, I think that the most 3 important features are the Stream API, Lambdas Expression and the Date/Time API.

Using the Code

Let us start with the Stream API which is the most important feature at all. With it, you are not obliged to use the loops and thanks to it, you have a more flexible solution.

This API makes simple processing collections and allows you to make more readable code.

You can understand the difference between the new feature and the traditional loops in this simple example:

C++
public Product getFirstFredProduct()
    {
      
        for (Product p : products)
        {
            if (p.getSellers().contains("Fred"))
            {
                return p ;
            }
        }
        return null ;
    }

Let us take a look at the new Stream API feature:

C++
public Optional<Product> getFirstFredProduct1()
    {

        return products.stream()
                .filter(product->product->getSellers().contains("Fred"))
                .findFirst();
    }

Now, let us move to the lambdas expression that every functional developer is very familiar with. Lamdas Expression or the best known as Closures is a concept that allows us to pass functions around and treat code as data like the example as below.

C++
Arrays.asList( "Sfax", "Tunisia",
"Tokyo","Japan" ).forEach( ( String e ) -> System.out.println( e ) );

Added to that, Date and Time are concerned by the new release of Java. There are many improvements in this API that its package contains all the classes for date, time, time zones, clock manipulations…

For example, we can get the local date and local time in this easy way:

C++
final LocalTime MyLocalTime = LocalTime.now();
final LocalTime ThetimeFromClock = LocalTime.now( clock );

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)