Tuesday, 6 March 2018

Java verison features

We have below features in Java 8 --- it is released in March 2014
  1.  Static and Default methods in Interface
  2. Base64 encoding and decoding
  3.  Java Time API
  4. Lambda Expressions

We have below features in Java7
  1. Switch case with String
  2. Diamond syntax
  3. Multi Catch Similar Exceptions
  4. Try with Resources
We have below features in Java 6

We have below features in Java 5

  1. For Each loop 
  2.  Auto Boxing and Un Boxing  
  3. Var Args
  4. Generics
  5. Annotaions
  6.  Static Import
Example of Static Import:

package com.sample.javase.testing;

public class StaticBlockTest {
   
    public static String s = "Static Import";

}

package com.sample.java.testing;

import static com.sample.javase.testing.StaticBlockTest.s;

import com.sample.javase.testing.StaticBlockTest;

public class StaticImportTest {

    public static void main(String[] args) {
        System.out.println(s);// with static import
        System.out.println(StaticBlockTest.s);// with out static import
    }
}

 Output:
Static Import
Static Import

Import Vs Static Import:

  • Import will help to access the classes of Package without fully qualify name(like OtherclassName oth;) where as static import will hep us to access static members of class without class qualification like(Classname.staticmember)
  • Import is to access classes and interfaces where as static import is to access static members of class.

No comments:

Post a Comment