JAVA 7 vs JAVA 8 vs JAVA 9 vs JAVA 10

Java 7- NEW IMPORTANT FEATURES
1- switch with string- 
i.e-
String a=”a”;
switch(a){
case “a”:sop(“f”);
break;

case “b”:sop(“s”);
break;

case default:

}

2-multi catch
Before java 7-
try{

}catch(ArithmeticException e){

}catch(Exception e){

}

After java 7-
try{

}catch(ArithmeticException | Exception e){

}

3- try with resources-

Before java 7-
try{
FileOutputStream fo=new FileOutputStream ();
}catch(IOException e){
}finally{
fo.close();
}

After java 7-

try(FileOutputStream fo=new FileOutputStream ()){

}catch(IOException e){
}finally{
}

4-Underscore with variable
long a=2345_3456_9012_9774L; 
int a=6_345;
(just for better readability)

5-Type Inference for Generic Instance-
Before java 7-

Map<String, List<String>> anagrams = new HashMap<String, List<String>>();

after java 7-

Map<String, List<String>> anagrams = new HashMap<>();

6- java.nio.file package-
Better support for file I/O and for accessing the file system.
A zip file system provider is also available in JDK 7.

 

Java 8- NEW IMPORTANT FEATURES
1-Functional Interfaces and Lambda Expressions-
@functionalInterface should be used on interface which have only one 1 abstract method.
– Lambda expression is a way to represent method implementation of functional interface.
Syntax –
(argument-list)->{body}
Before java 8-
Runnable r = new Runnable(){
@Override
public void run() {
System.out.println(“My Runnable”);
}};

After java 8-
Runnable r1 = () -> {
System.out.println(“My Runnable”);
};

2-Java Stream API for Bulk Data Operations on Collections-

-filter, sorted, toList, toSet, toMap, distinct, etc methods are included.

3- defaulft methods in interface
similar to non abstract methods, can be called without instance.

4- static methods in interface
static methods can be called on the name of interface.

5-forEach() method in Iterable interface
list.forEach(a->sop(a));

6- Java Time API Enhancements –
-addition of java.time package
-sub-packages java.time.format that provides classes to print and parse dates and times and java.time.zone provides support for time-zones and their rules.
-One of the useful class is DateTimeFormatter for converting datetime objects to strings.

7-Collection API improvements-
-Collection default method removeIf
Spliteterator– used to traverse elements sequentially or parallel.
-Map  replaceAll, compute, merge methods.

8-Concurrency API improvements-
ConcurrentHashmap- compute(), forEach(), forEachEntry(), forEachKey(), forEachValue(), merge(), reduce() and search() methods.

Others-

  1. JDBC-ODBC Bridge has been removed.
  2. PermGen memory space has been removed.

Java 9-NEW IMPORTANT FEATURES
1- Interface private methods
so default methods can share some methods.

2- collection factory methods –
ex- li.listOf(“a”, “b”, “c”);
setOf
mapOf.

java 10- NEW IMPORTANT FEATURES-

1- Variable type inference- so

var name= “kuldeep”;

is valid statement now.

Advertisements