JAVA 7 vs 8 vs 9 vs 10 vs 11 vs 12 vs 13

Java version list with dates : 

  • JDK 1.0 (January 23, 1996)
  • JDK 1.1 (February 19, 1996)
  • J2SE 1.2 (December 8, 1998)
  • J2SE 1.3 (May 8, 2000)
  • J2SE 1.4 (February 6, 2002)
  • J2SE 5.0 (September 30, 2004)
  • Java SE 6 (December 11, 2006)
  • Java SE 7 (July 28, 2011)
  • Java SE 8 (March 18, 2014)
  • Java SE 9 (September 21, 2017)
  • Java SE 10 (March 20, 2018)
  • Java SE 11 (September , 2018)
  • Java SE 12 (March 19, 2019)
  • Java SE 13 (September 17, 2019)

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.

Java 11- NEW IMPORTANT FEATURES-

1. Local-Variable Syntax for Lambda Parameters –
(x, y) -> x.process(y)
We’ll be able to write:
(var x, var y) -> x.process(y)

This expands Java 10 Local Variable Type Inference, that introduced a new syntax that reduces the verbosity associated with writing Java, while maintaining the commitment to static type safety.
In other words, you’ll be able to declare variables without having to specify the associated type.

2 – Other Changes in the existing classes:
A. New String Methods- strip(), stripLeading(),stripTrailing(),isBlank(),lines(),repeat(n)

B. Files Utility Methods- writeString(), readString(), isSameFile()

C. HTTP Client(Standard) – The new API supports both HTTP/1.1 and HTTP/2. It aims to replace the legacy HttpUrlConnection class.

Java 12- NEW IMPORTANT FEATURES-

  1. Switch Expressions –Classic switch statement:
    String result = "";
            switch (day) {
                case "M":
                case "W":
                case "F": {
                    result = "MWF";
                    break;
                }
                case "T":
                case "TH":
                case "S": {
                    result = "TTS";
                    break;
                }
            };
    
    Now in JAVA 12 : -
    String result = switch (day) {
                case "M", "W", "F" -> "MWF";
                case "T", "TH", "S" -> "TTS";
                default -> {
                    if(day.isEmpty())
                        break "Please insert a valid day.";
                    else
                        break "Looks like a Sunday.";
                }
            };
    
  2. File mismatch() Method – i.e. long mismatch = Files.mismatch(filePath1, filePath2);
  3. Java Strings New Methods : indent, transform,describeConstable, resolveConstantDesc.
  4. Pattern Matching for instanceof –The old way to typecast a type to another type is:
    if (obj instanceof String) {
        String s = (String) obj;
    }
    

    The new way is :

    if (obj instanceof String s) {
    // can use s directly here
    }

  5. Raw String Literals is Removed From JDK 12.

Java 13- NEW IMPORTANT FEATURES-

1-The addition of text blocks in a preview phase – A text block is a multi-line string literal that avoids the need for most escape sequences.

2-A second preview of switch expressions –  There had been one in JDK 12, but a change is slated to be made: to yield a value from a switch expression, the break with value statement is to be dropped in favor of a yield statement.

3-Enhancements to the ZGC –  (Z Garbage Collector) to return unused memory to the operating system.

Advertisements