Monday 17 January 2022

Java 8 features

 

Java 8 Programming Language Enhancements

Java 8 provides following features for Java Programming:

  • Lambda expressions,
  • Method references,
  • Functional interfaces (Consumer, Supplier, Predicate and Functions)
  • Stream API,
  • Base64 Encode Decode,
  • Default methods in interface
  • Static methods in interface,
  • Optional class,
  • Collectors class,
  • forEach() method,
  • Parallel Array Sorting,
  • Concurrency Enhancements,
  • Permanent Generation
Permanent Generation

Who has never configured their “PermSize” or their “MaxPermSize” JVM memory?

This was normally done after receiving those ugly “java.lang.OutOfMemoryError: PermGen error” errors.

This has now been replaced by something called Metaspace. The Metaspace will re-size itself depending on the demand we have of memory at runtime. If we need to, we can still tune the amount of Metaspace by setting the “MaxMetaspaceSize” param.

Functional interfaces

A functional interface is the one that defines exactly one abstract method. We have for instance “java.lang.Runnable” defining the run abstract method:

public abstract void run();
We can still add as many default methods (non abstract) as we like.

While defining a new functional interface, we will have to define the new annotation “@FunctionalInterface”. This will allow us to block bad usages of functional interfaces as it will not compile if used improperly with the new annotation.

No comments:

Post a Comment