Java 8 - Overview

JAVA 8 is a major feature release of JAVA programming.Java SE 8 was released in early 2014. In Java 8, about feature was lambda expressions.

Java 8 release, Java provided supports for functional programming stream API and new date/time API.

what is New Features of Java 8?

  • Lambda expression − Lambda expressions are not unknown to many of us who have worked on other popular programming languages like Scala. Adds functional processing capability to Java.

  • Functional Interface - Functional interfaces are also called Single Abstract Method interfaces (SAM Interfaces). permit exactly one abstract method

  • Default method − Interface to have default method implementation.

  • Stream API − Streams API in Java 8 supports a different type of iteration where you simply define the set of items to be processed, the operation(s) to be performed on each item, and where the output of those operations is to be stored. New stream API to facilitate pipeline processing.

  • Date Time API − Improved date time API.

Consider the following code snippet.

import java.util.Collections;
import java.util.List;
import java.util.ArrayList;
import java.util.Comparator;

public class Java8Tester {

    public static void main(String args[]) {

        List<String> names1 = new ArrayList<String>();
        names1.add("Jhonson ");
        names1.add("David ");
        names1.add("Angilina ");
        names1.add("Punit ");
        names1.add("Jhon ");

        List<String> names2 = new ArrayList<String>();
        names2.add("Jhonson ");
        names2.add("David ");
        names2.add("Angilina ");
        names2.add("Punit ");
        names2.add("Jhon ");

        Java8Tester tester = new Java8Tester();
        System.out.println("Sort using Java 7 syntax: ");

        System.out.println("Sort using Java 8 syntax: ");


    //sort using java 7
    private void sortUsingJava7(List<String> names) {
        Collections.sort(names, new Comparator<String>() {
            public int compare(String s1, String s2) {
                return s1.compareTo(s2);

    //sort using java 8
    private void sortUsingJava8(List<String> names) {
        Collections.sort(names, (s1, s2) -> s1.compareTo(s2));
Run example »

Run the program to get the following result.

$java -Xmx128M -Xms16M Java8Tester
Sort using Java 7 syntax: [Angilina , David , Jhon , Jhonson , Punit ] Sort using Java 8 syntax: [Angilina , David , Jhon , Jhonson , Punit ]

javacodegeeks is optimized for learning.© javacodegeeks .
All Right Reserved and you agree to have read and accepted our term and condition