Skip to main content

Posts

Showing posts from May, 2020

Functional Interface

What is Functional Interface? The functional interface is the only base for Lambda expression that is the lambda expression provides the implementation for the functional interface. The functional interface is a special type of interface that only contains a single abstract method and it is also known as SAM interface. In addition to a single abstract method, you can define any number of default and static methods within the functional interface.  Examples of a functional interface are all the interfaces present inside the package java.util.function and all those interfaces which are already present before Java 8 with a single abstract method like Runnable, Callable, Comparable, Comparator, etc. What does @FunctionalInterface annotation? The @FunctionalInterface annotation can guarantee that the interface has the only single abstract method and additionally it gives you an indication that this interface is a functional interface. It is like @Override annotation, which indicat...

Java 8 New Features List

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 ...

Lambda Expression

What is Lambda Expression? In java 8, a powerful concept is added named 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).  Lambda expression is that you can pass to a method whose argument type is functional interface i.e. an interface that is either annotated by @FunctionalInterface  annotation e.g. interfaces from java.util.function package, or an interface with a single abstract method e.g. Comparable, Comparator, Runnable, Callable, ActionListener, etc.  Lambda expression allows passing customized code to the java method that was not possible before java 8. Although before Java 8 the only option was to wrap your code as an object and pass it using anonymous inner class to the method. Lambda expression defines parameters and code that executed using those parameters. Let's take the simplest example of the lambda expression (String input) -> ...