SlideShare una empresa de Scribd logo
1 de 12
Descargar para leer sin conexión
Major New Language 
Features 
Neil Brown 10/2014 
@neiljbrown neiljbrown.com
Overview of Major New Features 
● Lambda expressions 
● Streams (aka bulk / aggregate data ops) 
● Default methods 
● Date/time API 
● Optional type
Lambda Expressions 
Anonymous function, with no class 
Expression syntax like that of a method 
(String s1, String s2) -> s1.length() - s2.length(); 
Assign to variables or pass as method param 
Benefits 
● Another means of code reuse 
● Terser implementation of single abstract methods (SAMs)
Streams API 
APIs support aggregating ‘streams’ on-the-fly, 
concurrently, using functional methods eg filter 
‘Stream’ - seq. of elements from a source 
supporting aggregating (‘bulk’) data operations 
Concept: 
● Convert source to stream 
● Process elements in parallel, concurrently 
● Collect resulting elements
Streams API 
Sources include Collections, Array, I/O classes 
Benefits 
● Better performance via lazy evaluation of 
methods on stream and parallel processing 
● Replace boilerplate external iteration code eg 
List<Student> students = new ArrayList<>(100); ... 
List<Student> filteredStudents = students.stream() 
.filter(s -> s.getDob().getYear() > yearOfBirthFilter) 
.collect(Collectors.toList());
Default Methods 
Interfaces can include default implementations 
interface Logger { 
default void info(String message) { 
Logger.log("[INFO]", message); 
} 
... 
} 
Compiler uses the ‘default method’ in classes 
which don’t provide own implementation
Default Methods 
Interfaces still not permitted to have state 
Benefit 
● Java APIs can evolve without breaking backwards 
compatibility eg add functional methods to Collection 
interfaces for Streams
Date & Time API 
java.time.* - 
Addresses issues with java.util.Date and Calendar 
● Thread-safe. Immutable classes. 
● Consistent design, inspired by Joda-Time 
● Better time-zone support 
Fluent API; Major classes: 
● LocalDateTime and ZonedDateTime - Factory 
methods, parsing, truncation 
● Period and Duration - lengths of time
java.util.Optional 
New type for value that may be null 
Used as method return type rather than null eg 
Optional<Soundcard> optionalSoundcard = computer.getSoundcard(); 
Forces client to deal with null at compile-time 
Provides convenience methods ifPresent(), orElse() for 
simpler handling of possible null 
Provides null-safe functional methods filter(), map() etc
java.util.Optional 
Benefits 
● More expressive / explicit API methods 
● Reduces no. of NullPointerException 
● Provided null safe methods reduce need for nested 
conditional statements to handle null refs
Code Examples 
Code examples for each new feature 
● https://bitbucket.org/neilbrown - ‘java8- 
examples’ repository 
Includes pre Java 8 equivalent code to help 
identify eligible cases
Questions? 
Thanks for attending 
Neil Brown 
@neiljbrown neiljbrown.com

Más contenido relacionado

La actualidad más candente

Presentation 1st
Presentation 1stPresentation 1st
Presentation 1st
Connex
 
Functional programming in scala
Functional programming in scalaFunctional programming in scala
Functional programming in scala
Stratio
 
Lex tool manual
Lex tool manualLex tool manual
Lex tool manual
Sami Said
 

La actualidad más candente (20)

Grokking Techtalk #38: Escape Analysis in Go compiler
 Grokking Techtalk #38: Escape Analysis in Go compiler Grokking Techtalk #38: Escape Analysis in Go compiler
Grokking Techtalk #38: Escape Analysis in Go compiler
 
Lambda Expressions in Java 8
Lambda Expressions in Java 8Lambda Expressions in Java 8
Lambda Expressions in Java 8
 
Lex & yacc
Lex & yaccLex & yacc
Lex & yacc
 
Presentation 1st
Presentation 1stPresentation 1st
Presentation 1st
 
Java 8 new features
Java 8 new featuresJava 8 new features
Java 8 new features
 
Functional programming in Scala
Functional programming in ScalaFunctional programming in Scala
Functional programming in Scala
 
LINQ/PLINQ
LINQ/PLINQLINQ/PLINQ
LINQ/PLINQ
 
What's new in Java 8
What's new in Java 8What's new in Java 8
What's new in Java 8
 
Practical Malware Analysis: Ch 6: Recognizing C Code Constructs in Assembly
Practical Malware Analysis: Ch 6: Recognizing C Code Constructs in AssemblyPractical Malware Analysis: Ch 6: Recognizing C Code Constructs in Assembly
Practical Malware Analysis: Ch 6: Recognizing C Code Constructs in Assembly
 
Java8 features
Java8 featuresJava8 features
Java8 features
 
Automate - Madhu Kanoor, Greg McCullough - ManageIQ Design Summit 2016
Automate - Madhu Kanoor, Greg McCullough - ManageIQ Design Summit 2016Automate - Madhu Kanoor, Greg McCullough - ManageIQ Design Summit 2016
Automate - Madhu Kanoor, Greg McCullough - ManageIQ Design Summit 2016
 
Can programming be liberated from the von neumann style?
Can programming be liberated from the von neumann style?Can programming be liberated from the von neumann style?
Can programming be liberated from the von neumann style?
 
Java 8
Java 8Java 8
Java 8
 
Yacc
YaccYacc
Yacc
 
Functional programming in scala
Functional programming in scalaFunctional programming in scala
Functional programming in scala
 
Java 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & StreamsJava 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & Streams
 
Java 8 - Project Lambda
Java 8 - Project LambdaJava 8 - Project Lambda
Java 8 - Project Lambda
 
Functional programming ideas in python
Functional programming ideas in pythonFunctional programming ideas in python
Functional programming ideas in python
 
Lex tool manual
Lex tool manualLex tool manual
Lex tool manual
 
Lambdas
LambdasLambdas
Lambdas
 

Similar a 2014 10 java 8 major new language features

Practices and tools for building better APIs
Practices and tools for building better APIsPractices and tools for building better APIs
Practices and tools for building better APIs
NLJUG
 
A-Brief-Introduction-To-JAVA8_By_Srimanta_Sahu
A-Brief-Introduction-To-JAVA8_By_Srimanta_SahuA-Brief-Introduction-To-JAVA8_By_Srimanta_Sahu
A-Brief-Introduction-To-JAVA8_By_Srimanta_Sahu
Srimanta Sahu
 
Software Uni Conf October 2014
Software Uni Conf October 2014Software Uni Conf October 2014
Software Uni Conf October 2014
Nayden Gochev
 
.NET 4 Demystified - Sandeep Joshi
.NET 4 Demystified - Sandeep Joshi.NET 4 Demystified - Sandeep Joshi
.NET 4 Demystified - Sandeep Joshi
Spiffy
 

Similar a 2014 10 java 8 major new language features (20)

Java 8
Java 8Java 8
Java 8
 
Lambdas in Java 8
Lambdas in Java 8Lambdas in Java 8
Lambdas in Java 8
 
java8
java8java8
java8
 
Improved Developer Productivity In JDK8
Improved Developer Productivity In JDK8Improved Developer Productivity In JDK8
Improved Developer Productivity In JDK8
 
Practices and tools for building better APIs
Practices and tools for building better APIsPractices and tools for building better APIs
Practices and tools for building better APIs
 
Practices and tools for building better API (JFall 2013)
Practices and tools for building better API (JFall 2013)Practices and tools for building better API (JFall 2013)
Practices and tools for building better API (JFall 2013)
 
What’s new in java 8
What’s new in java 8What’s new in java 8
What’s new in java 8
 
java150929145120-lva1-app6892 (2).pptx
java150929145120-lva1-app6892 (2).pptxjava150929145120-lva1-app6892 (2).pptx
java150929145120-lva1-app6892 (2).pptx
 
Java 8 presentation
Java 8 presentationJava 8 presentation
Java 8 presentation
 
Java SE 8 - New Features
Java SE 8 - New FeaturesJava SE 8 - New Features
Java SE 8 - New Features
 
A-Brief-Introduction-To-JAVA8_By_Srimanta_Sahu
A-Brief-Introduction-To-JAVA8_By_Srimanta_SahuA-Brief-Introduction-To-JAVA8_By_Srimanta_Sahu
A-Brief-Introduction-To-JAVA8_By_Srimanta_Sahu
 
Modern Java Features
Modern Java Features Modern Java Features
Modern Java Features
 
An Intro to Scala for PHP Developers
An Intro to Scala for PHP DevelopersAn Intro to Scala for PHP Developers
An Intro to Scala for PHP Developers
 
Effective Java, Third Edition - Keepin' it Effective
Effective Java, Third Edition - Keepin' it EffectiveEffective Java, Third Edition - Keepin' it Effective
Effective Java, Third Edition - Keepin' it Effective
 
Java SE 8 library design
Java SE 8 library designJava SE 8 library design
Java SE 8 library design
 
Software Uni Conf October 2014
Software Uni Conf October 2014Software Uni Conf October 2014
Software Uni Conf October 2014
 
Colloquium Report
Colloquium ReportColloquium Report
Colloquium Report
 
Java 8 New features
Java 8 New featuresJava 8 New features
Java 8 New features
 
Java8 training - Class 1
Java8 training  - Class 1Java8 training  - Class 1
Java8 training - Class 1
 
.NET 4 Demystified - Sandeep Joshi
.NET 4 Demystified - Sandeep Joshi.NET 4 Demystified - Sandeep Joshi
.NET 4 Demystified - Sandeep Joshi
 

Último

%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
chiefasafspells
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
masabamasaba
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 

Último (20)

%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 

2014 10 java 8 major new language features

  • 1. Major New Language Features Neil Brown 10/2014 @neiljbrown neiljbrown.com
  • 2. Overview of Major New Features ● Lambda expressions ● Streams (aka bulk / aggregate data ops) ● Default methods ● Date/time API ● Optional type
  • 3. Lambda Expressions Anonymous function, with no class Expression syntax like that of a method (String s1, String s2) -> s1.length() - s2.length(); Assign to variables or pass as method param Benefits ● Another means of code reuse ● Terser implementation of single abstract methods (SAMs)
  • 4. Streams API APIs support aggregating ‘streams’ on-the-fly, concurrently, using functional methods eg filter ‘Stream’ - seq. of elements from a source supporting aggregating (‘bulk’) data operations Concept: ● Convert source to stream ● Process elements in parallel, concurrently ● Collect resulting elements
  • 5. Streams API Sources include Collections, Array, I/O classes Benefits ● Better performance via lazy evaluation of methods on stream and parallel processing ● Replace boilerplate external iteration code eg List<Student> students = new ArrayList<>(100); ... List<Student> filteredStudents = students.stream() .filter(s -> s.getDob().getYear() > yearOfBirthFilter) .collect(Collectors.toList());
  • 6. Default Methods Interfaces can include default implementations interface Logger { default void info(String message) { Logger.log("[INFO]", message); } ... } Compiler uses the ‘default method’ in classes which don’t provide own implementation
  • 7. Default Methods Interfaces still not permitted to have state Benefit ● Java APIs can evolve without breaking backwards compatibility eg add functional methods to Collection interfaces for Streams
  • 8. Date & Time API java.time.* - Addresses issues with java.util.Date and Calendar ● Thread-safe. Immutable classes. ● Consistent design, inspired by Joda-Time ● Better time-zone support Fluent API; Major classes: ● LocalDateTime and ZonedDateTime - Factory methods, parsing, truncation ● Period and Duration - lengths of time
  • 9. java.util.Optional New type for value that may be null Used as method return type rather than null eg Optional<Soundcard> optionalSoundcard = computer.getSoundcard(); Forces client to deal with null at compile-time Provides convenience methods ifPresent(), orElse() for simpler handling of possible null Provides null-safe functional methods filter(), map() etc
  • 10. java.util.Optional Benefits ● More expressive / explicit API methods ● Reduces no. of NullPointerException ● Provided null safe methods reduce need for nested conditional statements to handle null refs
  • 11. Code Examples Code examples for each new feature ● https://bitbucket.org/neilbrown - ‘java8- examples’ repository Includes pre Java 8 equivalent code to help identify eligible cases
  • 12. Questions? Thanks for attending Neil Brown @neiljbrown neiljbrown.com