Monday, September 17, 2018

Whats new in Java 7 and Java 8

Java 8 is released much time back now, with the much awaited functional programming constructs, lambda expressions, streams api. Numerous other related enhancements like default functions, functional interfaces needed to be introduced to support above much wider and powerful constructs. Here is a summary of the enhancements.

It is to be noted that some of these feature are (borrowed or present) in the newer programming languages like scala or python.

Java 7 Features:

Code Conciseness, Redundancy:
  • Automatic type inference in generics instance creation.
  • try with resources for automatic cleanup of resources without the need of writing a finally block, if there is a finally block it is executed after the resources are auto cleaned up.
  • switch-case statements can work on string literals.
  • Multiple Exceptions can be caught in one catch block helping in code reuse.
Readability:
  • Numeric literals can contain _ for better readability
Performance and Concurrency:
  • JVM Performance improvements
  • Multithreaded custom class loaders
  • Concurrency Utilities - Fork/Join Framework, ThreadLocalRandom, Phaser class introduced similar to CyclicBarrier
Other Features:
  • SafeVarargs annotation
  • Internationalization support
  • Several enhancements in the Java swing framework

Java 8 Features:


Functional Programming:
  • Functional interfaces
  • Lambda expressions - treat functionality as method argument and code as data, instances of single method interfaces called functional interfaces.
  • Method references
Performance and Concurrency:
  • Sequential or parallel map reduce transformations.
  • Parallel Sorting using Arrays.parallelSort(). It uses fork/join pool introduced in java 7.
Annotations:
  • Repeating Annotations
  • Type annotations (annotations can now be added where-ever a Type is used)
New APIs:
  • New Stream API (java.util.stream) - provide functional style operations on a stream of elements, integrated with collections api to enable collections-stream conversion. 
  • Interfaces can now default and static methods avoiding the need of utility classes. e.g. forEach default method now in the "Collection" interface.
  • Java IO API improvements
  • Java Collection API improvements
  • New Date-Time package.
  • Java DB 10.10.
JVM:
  • PermGen is removed in HotSpot JVM.

Others:
  • Improved type inference when passing generic arguments
  • Method parameter reflection

No comments: