This article provides a summary of some of
the important Java 8 new features.
Java 8 is the newest release of Java and the
developer kit is JDK 8.
This is a significant upgrade to Java
language.
1. Introduction
of Lambda Expression
Lambda expression is a major change in java
as it changes how code is written in java and how solutions are conceptualized.
A lambda expression is a method without a
name, access-specifier or return value declaration.
Lambda expression add functional programming
features to java. This simplifies and greatly reduces the amount of code
written to achieve tasks.
A functional interface is an interface that
contains only one abstract method. Then main advantage of it is that it can be
used to refer to a lambda expression.
2. New
Stream API
Stream represents a flow of objects on which
operations can be performed. Primary aim of streams is to make the operations
easy on collections.
The newly added Stream api is available in
java.util.Stream package for creating and working with Streams.
It supports pipeline operations on data and
is optimized for Lambda expressions.
3. New
java.util.function package
This new package defines number of functional
interfaces that provide additional support for lambda expressions.
Predicates and Functions
A predicate is a function with a single
argument that returns a boolean value.
Functions are similar to Predicates, but
functions return an object as a result.
Both predicates and functions are useful
to evaluate lambda expressions.
4. Interface
default methods
Traditionally, interfaces contain
only constants and method signatures. They cannot contain method
implementations.
Beginning JDK 8, it is possible to define default implementation for a method
in an interface. These methods are called default methods.
A default method is declared using a keyword
“default” and it contains a method body.
A default method is available to all
implementing classes of the interface. If the implementation class wants to use
it, it can use it or it can ignore the default implementation and create its
own implementation.
5. New
Date Time api
A new Joda Time api was introduced in JDK 8
with the package java.time.
MetaSpace:
With JDK8, the permGen Space has been removed. So where will the metadata information be stored now? This metadata is now stored in a native memory are called as "MetaSpace". This memory is not a contiguous Java Heap memory. It allows for improvements over PermGen space in Garbage collection, auto tuning, concurrent de-allocation of metadata.
Difference between PermGen space and MetaSpace.
PermGen Space | MetaSpace |
---|---|
PermGen always has a fixed maximum size. | Metaspace by default auto increases its size depending on the underlying OS. |
Contiguous Java Heap Memory | Native Memory(provided by underlying OS) |
Max size can be set using XX:MaxPermSize | Max size can be set using XX:MetaspaceSize |
Comparatively ineffiecient Garbage collection. Frequent GC pauses and no concurrent deallocation. | Comparatively effiecient Garbage collection. Deallocate class data concurrently and not during GC pause. |
No comments:
Post a Comment