Java 10 & 11 Features


Java 10 was a short term release.


Major feature update of Java 10 was as follows

1.      Application data sharing, which means application classes can be saved to shared archive to improve startup and footprint.
2.      Improve G1 worst case latency by replacing it with full GC parallel.
3.      Garbage collector interface - clean garage collector interface is introduced to improve source code isolation.
4.      Remove the native header generator tool-it removes the javah tool from the jdk.
5.      Heap Allocation on Alternative Memory Devices:
It enables the HotSpot VM to allocate the Java object heap on an alternative memory device, such as an NV-DIMM, specified by the user


Java 11 features.

In Java 11 several methods are introduced to minimize developers coding efforts.


1.      String have new method, list of new methods are as follows
isBlank(), strip(), stripTrailing(), stripLeading(), repeat(int)

2.      Local variable type inference is introduced
For lambda var is used for implicit variable type.

   import java.time.Duration;
import java.util.concurrent.TimeUnit;
import java.util.stream.IntStream;

public class TestMain {
    
public static void main(String args[]){
        IntStream.of(
123567)
                .filter((
var i) -> i % 2 !0)
                .forEach(System.
out::println);
    }
}
3.      asMatchPredicate() new method, this method will create a predicate is pattern matches with string.
       
     4.      New method in Files class, to read and write string, readString(), writeString()
.
     5.Removal of thread functions: stop(Throwable obj) and destroy() objects have been removed  from  the JDK 11 because they only throw UnSupportedOperation and NoSuchMethodError  respectively.
    6. TimeUnit conversion – convert given time into YEAR, MONTH, DAY

  import java.time.Duration;
import java.util.concurrent.TimeUnit;

public class TestMain {
public static void main(String args[]){
   TimeUnit c = TimeUnit.DAYS;
   System.out.println(c.convert(Duration.ofHours(24))); //1
   System.out.println(c.convert(Duration.ofHours(48))); //2
   System.out.println(c.convert(Duration.ofHours(60))); //2
   }
 }

     7. Optional.isEmpty() This method returns true if the value of any object is null and else returns false.

  import java.time.Duration;
import java.util.Optional;
import java.util.concurrent.TimeUnit;

public class TestMain {
  
public static void main(String args[]) {
   Optional emptyOptional = Optional.empty();
   System.
out.println(emptyOptional.isEmpty()); //true
   Optional nonEmptyOptional = Optional.of(
"mk study journal");
   System.
out.println(nonEmptyOptional.isEmpty());  //false
    }
}
  


1 comment: