Why Java 8 ?

With this new release, Java 8 in 2014, java community has introduced a completely new JVM with full packed of some exciting features at both the JVM and programming language level.

There are literally dozens of new features that make java even better than previous versions and improvement about performance and optimized coding level with some functional programming features. These additions are under-the-hood improvements either at the compiler, JVM or help-system level.

  • Lambda Expression and Virtual Extension Methods are the highlighting feature of Java 8 which is the implementation of Lambda expressions and supporting features to the Java programming language and platform.
  • To overcome external iteration, Java 8 Stream API was introduced. We can use Java Stream API to implement internal iteration.
  • To use lambda expression, we need to create either our own functional interface or we can use pre-defined functional interface provided by Java-8 with @FunctionalInterface annotation.
  • Java 8 introduced forEach() and forEachOrdered() method to iterate over Collection and streams.
  • Internal iteration provides several features such as sequential and parallel execution with multithreaded environment.
  • Stream operations have two functional characteristics:

i) Pipelining and      ii) Internal Iteration

  • Java 8 added new Optional type gives developers most significant flexibility when dealing with null values, which reduces the likelihood of NullPointerExceptions.
  • In many cases, Java 8 will improve application performance without any specific work or tuning by using multithreaded environment.
  • Java 8 new Date and Time API will allow developers to handle date and time in a more efficient and natural way.
  • A new JavaScript engine “Nashhorn” is integrated with Java 8. When we integrate JS into backend that we don’t worthier about setting up node.js instance, we can simply use JVM to execute the code.
  • Concurrent Accumulators enable you to very efficiently increase / decrease the value of a counter in a thread safe manner. This is really a case where it’s not a question of taste, or preference – using these new classes in your code is really a no-brainer.
  • Java 8 provides Improved Security which replaces the existing hand-maintained list of caller sensitive methods with a mechanism that accurately identifies those methods and it allows its callers to be discovered reliably.
  • Aggregate operations: Streams support SQL-like operations and common operations from functional programing languages, such as filter, map, reduce, find, match, sorted, and so on. 
  • In Java 8 , static and default keyword to create interfaces with method implementation. forEach method implementation in Iterable interface is:
default void forEach(Consumer<? super T> action) {  
             Objects.requireNonNull(action); 
          for (T t : this) { 
         action.accept(t);
     }
}

Since, Java doesn’t provide multiple inheritance in Classes because it leads  to Diamond Problem. So how it will be handled with interfaces now, since interfaces are now similar to abstract classes.

  • parallelSort() method introduces with the multithreaded concept which makes it much faster than prevous sorting methods. The parallel sort uses Fork/Join framework.
  • Java 8 has introduced forEachmethod in java.lang.Iterable interface so that while writing code developers only focus on business logic only.
  • The :: operator is used to make method reference to separate the Class and Object from the method name.
e. g: str -> System.out.println(str)
             System.out::println 
  • A Part of these improvements java 8 improves some miscellaneous core API improvements Like:
    • ThreadLocal static method withInitial(Supplier supplier) to create instance easily.
    • min(), max() and sum() added in Integer, Long and double wrapper classes.
    • logicalAnd(), logicalOr() and logicalXor() methods in Boolean classes.
    • To invoke javascript “Nashrom” engine jjs command is added.
    • For Zip file entries,ZipFile.stream() method to get an ordered stream over zip file entries
    • Various utility methods added in Math classes.
    • Comparator interface extended with a lot of default and static methods for natural ordering or reverse order etc.
    • To analyze class files a new command “jdeps” has been added.
    • JDBC-ODBC bridge and PermGen (Permanent Generation) memory space has been removed.
    • jis command is added to invoke Nashorn Engine

Leave a Reply