Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Summary

Summary Java 8 New Featrues

Rating
-
Sold
-
Pages
34
Uploaded on
29-03-2023
Written in
2021/2022

Notes on Java 8 new and fantastic features , like - Lambda Expression - Functional Interfaces - Default methods - Predicates - Functions - Double colon operator (::) - Stream API - Date and Time API And much more exciting features

Show more Read less
Institution
Course

Content preview

Java 8 New Features In Simple Way DURGASOFT

Java 8 New Features
java 7 – July 28th 2011
2 Years 7 Months 18 Days

Java 8 - March 18th 2014

Java 9 - September 22nd 2016

Java 10 - 2018

After Java 1.5version, Java 8 is the next major version.
Before Java 8, sun people gave importance only for objects but in 1.8version oracle people gave the
importance for functional aspects of programming to bring its benefits to Java.ie it doesn’t mean Java
is functional oriented programming language.


Java 8 New Features:
1) Lambda Expression
2) Functional Interfaces
3) Default methods
4) Predicates
5) Functions
6) Double colon operator (::)
7) Stream API
8) Date and Time API
Etc…..




1

,Java 8 New Features In Simple Way DURGASOFT


Lambda (λ) Expression
☀ Lambda calculus is a big change in mathematical world which has been introduced in 1930.
Because of benefits of Lambda calculus slowly this concepts started using in programming world.
“LISP” is the first programming which uses Lambda Expression.

☀ The other languages which uses lambda expressions are:
 C#.Net
 C Objective
 C
 C++
 Python
 Ruby etc.
and finally in Java also.

☀ The Main Objective of Lambda Expression is to bring benefits of functional programming into
Java.

What is Lambda Expression (λ):
 Lambda Expression is just an anonymous (nameless) function. That means the function which
doesn’t have the name, return type and access modifiers.
 Lambda Expression also known as anonymous functions or closures.

Ex: 1
()  {
public void m1() { sop(“hello”);
sop(“hello”); }
} ()  { sop(“hello”); }
()  sop(“hello”);

Ex:2

public void add(inta, int b) {
sop(a+b); (inta, int b)  sop(a+b);
}

 If the type of the parameter can be decided by compiler automatically based on the context then
we can remove types also.
 The above Lambda expression we can rewrite as (a,b)  sop (a+b);




2

,Java 8 New Features In Simple Way DURGASOFT
Ex: 3

public String str(String str) { (String str)  return str;
return str;
}
(str)  str;

Conclusions:

1) A lambda expression can have zero or more number of parameters (arguments).

Ex:
()  sop(“hello”);
(int a )  sop(a);
(inta, int b)  return a+b;

2) Usually we can specify type of parameter. If the compiler expects the type based on the context
then we can remove type. i.e., programmer is not required.

Ex:
(inta, int b)  sop(a+b);

(a,b)  sop(a+b);

3) If multiple parameters present then these parameters should be separated with comma (,).

4) If zero number of parameters available then we have to use empty parameter [ like ()].

Ex: ()  sop(“hello”);

5) If only one parameter is available and if the compiler can expect the type then we can remove the
type and parenthesis also.

Ex:
(int a)  sop(a);

(a) sop(a);

A  sop(a);

6) Similar to method body lambda expression body also can contain multiple statements. If more
than one statements present then we have to enclose inside within curly braces. If one statement
present then curly braces are optional.

7) Once we write lambda expression we can call that expression just like a method, for this
functional interfaces are required.

3

, Java 8 New Features In Simple Way DURGASOFT


Functional Interfaces
If an interface contain only one abstract method, such type of interfaces are called functional
interfaces and the method is called functional method or single abstract method (SAM).

Ex:
1) Runnable  It contains only run() method
2) Comparable  It contains only compareTo() method
3) ActionListener  It contains only actionPerformed()
4) Callable  It contains only call() method

Inside functional interface in addition to single Abstract method (SAM) we write any number of
default and static methods.

Ex:

1) interface Interf {
2) public abstract void m1();
3) default void m2() {
4) System.out.println (“hello”);
5) }
6) }

In Java 8, Sun Micro System introduced @Functional Interface annotation to specify that the interface
is Functional Interface.

Ex:

@Functional Interface
Interface Interf { This code compiles without any compilation errors.
public void m1();
}

Inside Functional Interface we can take only one abstract method, if we take more than one abstract
method then compiler raise an error message that is called we will get compilation error.

Ex:

@Functional Interface {
public void m1(); This code gives compilation error.
public void m2();
}



4

Written for

Course

Document information

Uploaded on
March 29, 2023
Number of pages
34
Written in
2021/2022
Type
SUMMARY

Subjects

$10.99
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
HarryStark

Get to know the seller

Seller avatar
HarryStark (self)
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
3 year
Number of followers
0
Documents
2
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions