Difference between revisions of "Java 8"

(Created page with "===Lambda Expressions=== ===Collections=== ===Date and Time===")
 
Line 1: Line 1:
===[[Lambda Expressions]]===
+
===What are the new features introduced in JAVA 8?===
===[[Collections]]===
+
There are dozens of features added to Java 8, the most significant ones are mentioned below −
===[[Date and Time]]===
+
 
 +
*'''Lambda expression''' − Adds functional processing capability to Java.
 +
*'''Method references''' − Referencing functions by their names instead of invoking them directly. Using functions as parameter.
 +
*'''Default method''' − Interface to have default method implementation.
 +
*'''New tools''' − New compiler tools and utilities are added like 'jdeps' to figure out dependencies.
 +
*'''Stream API''' − New stream API to facilitate pipeline processing.
 +
*'''Date Time API''' − Improved date time API.
 +
*'''Optional''' − Emphasis on best practices to handle null values properly.
 +
*'''Nashorn, JavaScript Engine''' − A Java-based engine to execute JavaScript code.
 +
 
 +
Along with these new featuers, lots of feature enhancements are done under-the-hood, at both compiler and JVM level.
 +
 
 +
===What are default methods?===
 +
With java 8, an interface can have default implementation of a function in interfaces.
 +
 
 +
===What are static default methods?===
 +
An interface can also have static helper methods from Java 8 onwards.
 +
<syntaxhighlight lang="java">
 +
public interface vehicle {
 +
  default void print() {
 +
      System.out.println("I am a vehicle!");
 +
  }
 +
 +
  static void blowHorn() {
 +
      System.out.println("Blowing horn!!!");
 +
  }
 +
}
 +
</syntaxhighlight>

Revision as of 04:55, 5 June 2018

What are the new features introduced in JAVA 8?

There are dozens of features added to Java 8, the most significant ones are mentioned below −

  • Lambda expression − Adds functional processing capability to Java.
  • Method references − Referencing functions by their names instead of invoking them directly. Using functions as parameter.
  • Default method − Interface to have default method implementation.
  • New tools − New compiler tools and utilities are added like 'jdeps' to figure out dependencies.
  • Stream API − New stream API to facilitate pipeline processing.
  • Date Time API − Improved date time API.
  • Optional − Emphasis on best practices to handle null values properly.
  • Nashorn, JavaScript Engine − A Java-based engine to execute JavaScript code.

Along with these new featuers, lots of feature enhancements are done under-the-hood, at both compiler and JVM level.

What are default methods?

With java 8, an interface can have default implementation of a function in interfaces.

What are static default methods?

An interface can also have static helper methods from Java 8 onwards.

public interface vehicle {
   default void print() {
      System.out.println("I am a vehicle!");
   }
 
   static void blowHorn() {
      System.out.println("Blowing horn!!!");
   }
}