Java 8 (1.8) New Features

Java 8 (1.8) New Features

- Oracle released a new version of Java as Java 8 in March 18, 2014. 

- Java Platform, Standard Edition 8 is a major feature release.

 Java 8 Programming Language Enhancements

Java 8 provides following features for Java Programming:
  • Lambda expressions,
  • Method references,
  • Functional interfaces,
  • Stream API,
  • Default methods,
  • Base64 Encode Decode,
  • Static methods in interface,
  • Optional class,
  • Collectors class,
  • ForEach() method,
  • Parallel array sorting,
  • Nashorn JavaScript Engine,
  • Type and Repeating Annotations,
  • IO Enhancements,
  • Concurrency Enhancements,
  • JDBC Enhancements etc.

Without Lambda Expression

  1. interface Drawable{  
  2.     public void draw();  
  3. }  
  4. public class LambdaExpressionExample {  
  5.     public static void main(String[] args) {  
  6.         int width=10;  
  7.   
  8.         //without lambda, Drawable implementation using anonymous class  
  9.         Drawable d=new Drawable(){  
  10.             public void draw(){System.out.println("Drawing "+width);}  
  11.         };  
  12.         d.draw();  
  13.     }  
------------------------------------
OUTPUT:- Drawing 10


Java Lambda Expression Example

  1. @FunctionalInterface  //It is optional  
  2. interface Drawable{  
  3.     public void draw();  
  4. }  
  5.   
  6. public class LambdaExpressionExample2 {  
  7.     public static void main(String[] args) {  
  8.         int width=10;  
  9.           
  10.         //with lambda  
  11.         Drawable d2=()->{  
  12.             System.out.println("Drawing "+width);  
  13.         };  
  14.         d2.draw();  
  15.     }  
-----------------------------------------
 OUTPUT:-  Drawing 10


 

 

Comments

Popular posts from this blog

Introducing Windows Azure WebJobs (My senior research)

Understanding Oauth2 (you have a option of login)