SlideShare una empresa de Scribd logo
1 de 25
Descargar para leer sin conexión
What’s New in Java 8
Lambda, Default Methods, and Streams
What’s New in Java 8
● Lambda Expression
● Default Methods
● Streams
● Optional
● Nashorn
● New Date and Time API
● No More PermGen
What’s New in Java 8
● Lambda Expression
● Default Methods
● Streams
● Optional
● Nashorn
● New Date and Time API
● No More PermGen
Java 9 has been scheduled for general
availability in 2017
Lambda Expression and Method Reference
Lambda Expression
A lambda expression is like syntactic sugar for
an anonymous class with one method
Lambda Expression - Syntax
() -> body
parameter -> body
(parameters) -> body
Lambda Expression - Syntax Example
() -> { System.out.println(“Hello”); }
(int i) -> System.out.println(i)
(double d1, double d2) -> Double.compare(d1, d2)
Lambda Expression - Method References
A method references is the shorthand syntax
for a lambda expression that executes just one
method
Lambda Expression - Method References
Sometimes lambda expression is just a call to some method
list.forEach(s -> System.out.println(s));
Lambda Expression - Method References
You can turn that lambda expression into method reference
list.forEach(System.out::println);
Lambda Expression - Method References
Consumer<String> consumer = (s) -> {
System.out.println(s)
};
Consumer<String> consumer = System.out::println;
Default Methods
Default Methods
Default methods enable you to add new
functionality to the interfaces of your libraries
and ensure binary compatibility with code
written for older versions of those interfaces.
Default Methods - Example
public interface Iterable<T> {
Iterator<T> iterator();
default void forEach(Consumer<? super T> action) {
Objects.requireNonNull(action);
for (T t : this) { action.accept(t); }
}
default Spliterator<T> spliterator() { ... }
}
Static Methods
You can define static methods in interfaces!
Static Methods - Example
public interface Vertx extends Measured {
static Vertx vertx() {
return factory.vertx();
}
...
VertxFactory factory =
ServiceHelper.loadFactory(VertxFactory.class);
}
Static Methods - Example
Vertx vertx = Vertx.vertx();
Static Methods - Example
Vertx vertx =
Vertx.vertx();
Streams
Streams
A sequence of elements supporting sequential
and parallel aggregate operations.
Streams - Example
int sum = widgets.stream()
.filter(w -> w.getColor() == RED)
.mapToInt(w -> w.getWeight())
.sum();
Streams - Example
int sum = widgets.parallelStream()
.filter(w -> w.getColor() == RED)
.mapToInt(w -> w.getWeight())
.sum();
?
Thank You

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Matlab m files and scripts
Matlab m files and scriptsMatlab m files and scripts
Matlab m files and scripts
 
Consuming and Creating Libraries in C++
Consuming and Creating Libraries in C++Consuming and Creating Libraries in C++
Consuming and Creating Libraries in C++
 
11 ruby methods
11 ruby methods11 ruby methods
11 ruby methods
 
Oct.22nd.Presentation.Final
Oct.22nd.Presentation.FinalOct.22nd.Presentation.Final
Oct.22nd.Presentation.Final
 
Unit iii
Unit iiiUnit iii
Unit iii
 
C intro
C introC intro
C intro
 
Function in C++
Function in C++Function in C++
Function in C++
 
Matlab Programming Tips Part 1
Matlab Programming Tips Part 1Matlab Programming Tips Part 1
Matlab Programming Tips Part 1
 
Ch08
Ch08Ch08
Ch08
 
Ch13
Ch13Ch13
Ch13
 
Basic of Python- Hands on Session
Basic of Python- Hands on SessionBasic of Python- Hands on Session
Basic of Python- Hands on Session
 
Lex (lexical analyzer)
Lex (lexical analyzer)Lex (lexical analyzer)
Lex (lexical analyzer)
 
C
CC
C
 
Matlab Functions
Matlab FunctionsMatlab Functions
Matlab Functions
 
Lab5
Lab5Lab5
Lab5
 
Java8
Java8Java8
Java8
 
Modern C++
Modern C++Modern C++
Modern C++
 
An Introduction to MATLAB for beginners
An Introduction to MATLAB for beginnersAn Introduction to MATLAB for beginners
An Introduction to MATLAB for beginners
 
Unit v
Unit vUnit v
Unit v
 
LISP: Input And Output
LISP: Input And OutputLISP: Input And Output
LISP: Input And Output
 

Similar a What's new in java 8

Similar a What's new in java 8 (20)

Java 8 presentation
Java 8 presentationJava 8 presentation
Java 8 presentation
 
Java 8 Intro - Core Features
Java 8 Intro - Core FeaturesJava 8 Intro - Core Features
Java 8 Intro - Core Features
 
Java 8 New features
Java 8 New featuresJava 8 New features
Java 8 New features
 
Introduction to Java 8
Introduction to Java 8Introduction to Java 8
Introduction to Java 8
 
New features in jdk8 iti
New features in jdk8 itiNew features in jdk8 iti
New features in jdk8 iti
 
java150929145120-lva1-app6892 (2).pptx
java150929145120-lva1-app6892 (2).pptxjava150929145120-lva1-app6892 (2).pptx
java150929145120-lva1-app6892 (2).pptx
 
New Features in JDK 8
New Features in JDK 8New Features in JDK 8
New Features in JDK 8
 
Java8: what's new and what's hot
Java8: what's new and what's hotJava8: what's new and what's hot
Java8: what's new and what's hot
 
Colloquium Report
Colloquium ReportColloquium Report
Colloquium Report
 
Functional programming in java 8 by harmeet singh
Functional programming in java 8 by harmeet singhFunctional programming in java 8 by harmeet singh
Functional programming in java 8 by harmeet singh
 
Major Java 8 features
Major Java 8 featuresMajor Java 8 features
Major Java 8 features
 
Java 8 Workshop
Java 8 WorkshopJava 8 Workshop
Java 8 Workshop
 
Java 8 features
Java 8 featuresJava 8 features
Java 8 features
 
JDK8 Lambdas and Streams: Changing The Way You Think When Developing Java
JDK8 Lambdas and Streams: Changing The Way You Think When Developing JavaJDK8 Lambdas and Streams: Changing The Way You Think When Developing Java
JDK8 Lambdas and Streams: Changing The Way You Think When Developing Java
 
Java8.part2
Java8.part2Java8.part2
Java8.part2
 
Java gets a closure
Java gets a closureJava gets a closure
Java gets a closure
 
Java8
Java8Java8
Java8
 
Automatic Migration of Legacy Java Method Implementations to Interfaces
Automatic Migration of Legacy Java Method Implementations to InterfacesAutomatic Migration of Legacy Java Method Implementations to Interfaces
Automatic Migration of Legacy Java Method Implementations to Interfaces
 
Lambdas in Java 8
Lambdas in Java 8Lambdas in Java 8
Lambdas in Java 8
 
Java 8 new features
Java 8 new featuresJava 8 new features
Java 8 new features
 

Último

Último (20)

AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 

What's new in java 8

  • 1. What’s New in Java 8 Lambda, Default Methods, and Streams
  • 2. What’s New in Java 8 ● Lambda Expression ● Default Methods ● Streams ● Optional ● Nashorn ● New Date and Time API ● No More PermGen
  • 3. What’s New in Java 8 ● Lambda Expression ● Default Methods ● Streams ● Optional ● Nashorn ● New Date and Time API ● No More PermGen
  • 4. Java 9 has been scheduled for general availability in 2017
  • 5. Lambda Expression and Method Reference
  • 6. Lambda Expression A lambda expression is like syntactic sugar for an anonymous class with one method
  • 7. Lambda Expression - Syntax () -> body parameter -> body (parameters) -> body
  • 8. Lambda Expression - Syntax Example () -> { System.out.println(“Hello”); } (int i) -> System.out.println(i) (double d1, double d2) -> Double.compare(d1, d2)
  • 9. Lambda Expression - Method References A method references is the shorthand syntax for a lambda expression that executes just one method
  • 10. Lambda Expression - Method References Sometimes lambda expression is just a call to some method list.forEach(s -> System.out.println(s));
  • 11. Lambda Expression - Method References You can turn that lambda expression into method reference list.forEach(System.out::println);
  • 12. Lambda Expression - Method References Consumer<String> consumer = (s) -> { System.out.println(s) }; Consumer<String> consumer = System.out::println;
  • 14. Default Methods Default methods enable you to add new functionality to the interfaces of your libraries and ensure binary compatibility with code written for older versions of those interfaces.
  • 15. Default Methods - Example public interface Iterable<T> { Iterator<T> iterator(); default void forEach(Consumer<? super T> action) { Objects.requireNonNull(action); for (T t : this) { action.accept(t); } } default Spliterator<T> spliterator() { ... } }
  • 16. Static Methods You can define static methods in interfaces!
  • 17. Static Methods - Example public interface Vertx extends Measured { static Vertx vertx() { return factory.vertx(); } ... VertxFactory factory = ServiceHelper.loadFactory(VertxFactory.class); }
  • 18. Static Methods - Example Vertx vertx = Vertx.vertx();
  • 19. Static Methods - Example Vertx vertx = Vertx.vertx();
  • 21. Streams A sequence of elements supporting sequential and parallel aggregate operations.
  • 22. Streams - Example int sum = widgets.stream() .filter(w -> w.getColor() == RED) .mapToInt(w -> w.getWeight()) .sum();
  • 23. Streams - Example int sum = widgets.parallelStream() .filter(w -> w.getColor() == RED) .mapToInt(w -> w.getWeight()) .sum();
  • 24. ?