Java SE 8 is released on 18th March 2014 and it is the most powerful release to enable functional programming. Java SE 8 is one of the releases which has numerous totally new features.
In this post, we will have a look at those new features of java 8 in brief. Some other small changes and bug fixes are also available as a part of java 8. Focus the following list of java 8 new features.
- Lambda Expression
- Functional Interface
- Default and static methods inside the interface
- Predefined functional interfaces(Predicates, Function, Consumer, etc).
- Double(::) operator
- Stream API
- Date & Time API(Joda API)
Main Objectives of Java 8
- To simplify the way of writing code or to simplify the programming.
- To utilize the benefits of functional programming using a lambda expression. Remember java 8 is still object-oriented programing language.
- To enable parallel programming or parallel processing in java.
1. Lambda Expression
Lambda expression is an anonymous function (a nameless function that does not have a modifier, return type, and even the type of its arguments). Java compiler infers the name, type of arguments, and return type from the functional interface method. Lambda expression gives you the power to pass the customize code to your java method. Click here to read more.
2. Functional Interface
The functional interface contains only a single abstract method also known as SAM. For example Runnable, Callable, Comparable, etc. But It can contain any number of default and static methods.
Lambda expression provides the implementation of the functional interface. Click here to read more.
3. Default and Static methods inside Interface
Before Java 8, we could not define static and default methods inside an interface. But from java 8, we can define n numbers of static and default methods inside the interface. Default methods are declared with the default keyword at the beginning of the method signature and then provide an implementation of the method. Click here to read more.
4. Predefined Functional Interfaces
Java 8 provided a lot of predefined functional interfaces for utilizing the benefits of functional programming using lambda expression and method reference. These interfaces are present inside the package java.util.function and annotated with @FunctionalInterface. Click here to read more.
5. Double (::) Operator
Java 8 double (::) operator knows as method reference, is used for the method or constructor reference.
Java 8 provides four types of method reference (i) static method reference (ii) instance method reference for a specific object (iii) constructor reference (iv) instance method reference for an arbitrary object of a specific type. Click here to read more.
6. Stream API
Java 8 Stream(Interface present inside java.util.stream) is a series of objects which is obtained from the collection or from a group of values. Stream API is used for processing the collection of objects or groups of values efficiently and allows us to execute multiple operations on it. There are a lot of operations that can be performed on the stream for example map, filter, sorted, collect, foreach, etc. Click here to read more.
7. Date & Time API(Joda Time API)
The date & time API has defined several classes and interfaces to handle the date and time effectively. This API also know as Joda Time API(developed by joda.org) and the classes/interfaces of this API are present inside java.time package. Click here to read more.
Thank you so much for reading this post. This is the brief introduction for the java 8 new features and you can read more by using the link given inside every point. Please comment below if there is any query or feedback. I will try to respond back.
Nice one
ReplyDelete