We have below features in Java 8 --- it is released in March 2014
We have below features in Java7
We have below features in Java 5
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:
- Static and Default methods in Interface
- Base64 encoding and decoding
- Java Time API
- Lambda Expressions
We have below features in Java7
- Switch case with String
- Diamond syntax
- Multi Catch Similar Exceptions
- Try with Resources
We have below features in Java 5
- For Each loop
- Auto Boxing and Un Boxing
- Var Args
- Generics
- Annotaions
- 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