SlideShare ist ein Scribd-Unternehmen logo
1 von 29
Downloaden Sie, um offline zu lesen
10+ new features
you ought to know
using Java 8
Oleg Tsal-Tsalko
JavaDay Lviv 2015
LEAD SOFTWARE ENGINEER AT EPAM SYSTEMS.
PATIONATE DEVELOPER, SPEAKER, ACTIVE MEMBER OF
KIEV JUG.
PARTICIPATE IN DIFFERENT EDUCATIONAL INITIATIVES,
ENGINEERING EVENTS AND JCP/ADOPTJSR PROGRAMS.
OLEG TSAL-TSALKO
ABOUT ME
3CONFIDENTIAL
•  Stream API
•  Lambdas and method references
•  Default methods
•  Optional values
•  Date & Time API
•  Stamped Locks and Concurrent Adders
•  Type annotations and repeated annotations
•  New files operations
•  Overflow operations and Base64 encoding
•  Nashorn JavaScript engine
Agenda
4CONFIDENTIAL
•  An abstraction that supports bulk operations
over sequence of elements
•  Not a data structure
•  Simple and logical chaining of operations
•  Lazy evaluation
•  Internal parallelism if required
•  Concept of functional programming in Java
#1 Stream API
5CONFIDENTIAL
•  Collection.stream()
•  IntStream.range()
•  Stream.of()
•  Arrays.stream()
•  BufferedReader.lines()
•  CharSequence.chars()
•  Pattern.splitAsStream()
How can I get a Stream?
6CONFIDENTIAL
Fluent and simple
txns.stream()
.filter(t ->t.getBuyer().getAge()>=65)
.map(Txn::getSeller)
.distinct()
.sort(comparing(Seller::getName))
.forEach(s -> System.out.println(s.getName());
7CONFIDENTIAL
java.util.function Package:
Predicate<T>
Determine if the input of type T matches some criteria
Consumer<T>
Accept a single input argument of type T, and return no result
Function<T, R>
Apply a function to the input type T, generating a result of type R
java.util.stream Package:
Collector<T, A, R>
Used to collect stream of elements of type T into single result of
type R
Collectors
Contains number of predefined Collectors
Functional interfaces
8CONFIDENTIAL
A lambda expression is an anonymous function
–  Argument list, a return type, and a body
(Object o) -> o.toString()
–  Method reference
Object::toString
–  Capture value from enclosing context
(Person p) ->p.getName().equals(name)
–  Type inference
p -> p.getName().equals(name)
–  Forget to use anonymous classes
You can now pass behavior as a data between your objects
#2 Lambdas
9CONFIDENTIAL
#3 Method reference
FileFilter x = (File f) -> f.canRead();
FileFilter x = File::canRead;
FileFilter x = new FileFilter() {
public boolean accept(File f) {
return f.canRead();
}
};
10CONFIDENTIAL
Since Java doesn’t have Function type on it’s own
Lambda’s type evaluated to some Functional
interface:
Runnable r = () -> { doSmth(); };
Callable c = () -> calcResult();
Comparator comp = (o1, o2) -> compare(o1, o2);
What’s your type?
11CONFIDENTIAL
Influence on existing classes
java.lang.Iterable#forEach()
java.util.Collection#stream()
java.util.Collection#parallelStream()
java.util.Comparator#comparing(…)
java.util.Comparator#thenComparing(…)
java.util.Comparator#reverse()
…
12CONFIDENTIAL
SHOW ME THE CODE
Lambdas and streams
TALK IS CHEAP
13CONFIDENTIAL
•  Libraries need to evolve, or they stagnate
•  Java preserves compatibility
•  Multiple inheritance in Java?
•  Default methods can reduce implementation
burden
•  Resolution rules:
– Class wins over interface
– More specific subclass wins
– No 3rd rule
#4 Default methods
14CONFIDENTIAL
•  Annoyed by NPEs?
•  Should your method return null or throw
RuntimeException?
•  Wondering how to implement SpecialCase
pattern?
•  Inspired by functional programming and want to
build a method chain for NULL handling?
=> You are lucky with Java 8…
#5 Optional
15CONFIDENTIAL
#6 Date & Time API
•  Replaces old ambiguous java.util.Date,
Calendar, TimeZone, DateFormat classes
with lots of deprecations
•  More fluent/simple/clean API
•  Immutable classes
•  Using Java8 features including lambdas
•  Precise separation of concepts
16CONFIDENTIAL
•  LocalDate – a date only
•  LocalTime – a time only
•  LocalDateTime – date with time
•  ZonedDateTime – date with time in time zone
•  Period - date-based amount of time
•  Duration - time-based amount of time
•  And more…
Range of types
17CONFIDENTIAL
Time Zones
If you can avoid using TimeZones – do it!
If not – use ZonedDateAndTime!
18CONFIDENTIAL
•  ZoneId – replacement for TimeZone class (e.g.
“Europe/London”, “Europe/Kiev”)
•  ZoneOffset – representing offset from UTC time
•  ZoneRules – behind the scenes class which
defines time zone rules
•  ZonedDateTime – main date/time class which is
aware of time zones
TimeZone classes in Java 8
19CONFIDENTIAL
New API is very flexible because it based on number of
abstractions at it’s bottom:
Temporal – parent class for all date/time objects which
defines mutation operation for them such as plus/minus/
with
TemporalAdjuster – functional interface which responsible
for mutating Temporal objects
TemporalField – represents parts/fields of date/time
objects such as (DAY_OF_WEEK, MONTH, etc.)
TemporalUnit – represents type of date/time values such as
(MINUTES, DAYS, YEARS, etc.)
TemporalAmount – class which represents amount of time
Power of abstraction
20CONFIDENTIAL
SHOW ME THE CODE
Optional and Date and Time API
TALK IS CHEAP
21CONFIDENTIAL
•  Whenever we think of using RWLock
•  RWLock can cause starvation of readers
•  RWLock is pessimistic on reads
•  Read lock is optimistic
•  Optimistic lock can be converted to pessimistic
lock if necessary
•  Write locks are always pessimistic
#7 StampedLock
22CONFIDENTIAL
•  [Java 5] When readers are given priority,
then writers might never be able to
complete
•  [Java 6] But when writers are given
priority, readers might be starved
⇒ In Java 8 use StampedLock instead!
RWLock starvation
23CONFIDENTIAL
•  Pros
– Has much better performance than
ReentrantReadWriteLock
– Latest versions do not suffer from starvation
of writers
•  Cons
– Idioms are more difficult to get right than
with ReadWriteLock
– A small difference can make a big difference
in performance
StampedLock
24CONFIDENTIAL
How would you implement counter in
multithreaded environment?
•  Dirty counters (silly)
•  Synchronized (very slow)
•  RWLock (slow)
•  Volatile (only if you have 1 writer/updater)
•  AtomicInteger (yes, before Java 8…)
⇒  LongAdder in Java 8!
#8 Concurrent Adders
25CONFIDENTIAL
WANT MORE?
26CONFIDENTIAL
9 Improved annotations
10 New file operations
11 Overflow operations
12 Base64 encoding
13 Nashorn JavaScript engine
27CONFIDENTIAL
•  Process Termination
•  Strong Random Generation
•  Date.toInstant()
•  Interface static methods
•  Better Type Inference
•  Parameter names support by compiler
•  Parallel Arrays
•  Nashorn CLI JavaScript interpriter
•  Class dependency analyzer
However there are even more…
28CONFIDENTIAL
•  https://www.google.com/?gws_rd=ssl
•  https://github.com/RichardWarburton/java-8-
lambdas-exercises
•  http://javaspecialists.eu/talks/jfokus13/
PhaserAndStampedLock.pdf
•  http://www.javacodegeeks.com/2014/05/
java-8-features-tutorial.html
•  http://blog.takipi.com/10-features-in-java-8-
you-havent-heard-of/
Resources
29CONFIDENTIAL
QUESTIONS?
Skype: oleg.tsalko
Twitter: @tsaltsol
THANK YOU

Weitere ähnliche Inhalte

Was ist angesagt?

55 New Features in Java SE 8
55 New Features in Java SE 855 New Features in Java SE 8
55 New Features in Java SE 8Simon Ritter
 
The Dark Side Of Lambda Expressions in Java 8
The Dark Side Of Lambda Expressions in Java 8The Dark Side Of Lambda Expressions in Java 8
The Dark Side Of Lambda Expressions in Java 8Takipi
 
Java 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & StreamsJava 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & StreamsNewCircle Training
 
Lambda Expressions in Java 8
Lambda Expressions in Java 8Lambda Expressions in Java 8
Lambda Expressions in Java 8icarter09
 
New Features Of JDK 7
New Features Of JDK 7New Features Of JDK 7
New Features Of JDK 7Deniz Oguz
 
Functional programming with Java 8
Functional programming with Java 8Functional programming with Java 8
Functional programming with Java 8LivePerson
 
Programming with Lambda Expressions in Java
Programming with Lambda Expressions in Java Programming with Lambda Expressions in Java
Programming with Lambda Expressions in Java langer4711
 
Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)
Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)
Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)DevelopIntelligence
 
Lambda Expressions in Java
Lambda Expressions in JavaLambda Expressions in Java
Lambda Expressions in JavaErhan Bagdemir
 
Java 8 - Project Lambda
Java 8 - Project LambdaJava 8 - Project Lambda
Java 8 - Project LambdaRahman USTA
 
Refactoring to Scala DSLs and LiftOff 2009 Recap
Refactoring to Scala DSLs and LiftOff 2009 RecapRefactoring to Scala DSLs and LiftOff 2009 Recap
Refactoring to Scala DSLs and LiftOff 2009 RecapDave Orme
 
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 singhHarmeet Singh(Taara)
 

Was ist angesagt? (20)

55 New Features in Java SE 8
55 New Features in Java SE 855 New Features in Java SE 8
55 New Features in Java SE 8
 
Java SE 8 library design
Java SE 8 library designJava SE 8 library design
Java SE 8 library design
 
The Dark Side Of Lambda Expressions in Java 8
The Dark Side Of Lambda Expressions in Java 8The Dark Side Of Lambda Expressions in Java 8
The Dark Side Of Lambda Expressions in Java 8
 
Java 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & StreamsJava 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & Streams
 
Java 8 lambda
Java 8 lambdaJava 8 lambda
Java 8 lambda
 
Introduction to new features in java 8
Introduction to new features in java 8Introduction to new features in java 8
Introduction to new features in java 8
 
Lambda Expressions in Java 8
Lambda Expressions in Java 8Lambda Expressions in Java 8
Lambda Expressions in Java 8
 
Major Java 8 features
Major Java 8 featuresMajor Java 8 features
Major Java 8 features
 
Java 8 features
Java 8 featuresJava 8 features
Java 8 features
 
Java SE 8
Java SE 8Java SE 8
Java SE 8
 
New Features Of JDK 7
New Features Of JDK 7New Features Of JDK 7
New Features Of JDK 7
 
Functional programming with Java 8
Functional programming with Java 8Functional programming with Java 8
Functional programming with Java 8
 
Programming with Lambda Expressions in Java
Programming with Lambda Expressions in Java Programming with Lambda Expressions in Java
Programming with Lambda Expressions in Java
 
Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)
Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)
Whats New in Java 5, 6, & 7 (Webinar Presentation - June 2013)
 
Smart Migration to JDK 8
Smart Migration to JDK 8Smart Migration to JDK 8
Smart Migration to JDK 8
 
Lambda Expressions in Java
Lambda Expressions in JavaLambda Expressions in Java
Lambda Expressions in Java
 
Java 8 - Project Lambda
Java 8 - Project LambdaJava 8 - Project Lambda
Java 8 - Project Lambda
 
Java 8
Java 8Java 8
Java 8
 
Refactoring to Scala DSLs and LiftOff 2009 Recap
Refactoring to Scala DSLs and LiftOff 2009 RecapRefactoring to Scala DSLs and LiftOff 2009 Recap
Refactoring to Scala DSLs and LiftOff 2009 Recap
 
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
 

Ähnlich wie 10+ new Java 8 features you need to know

Java Closures
Java ClosuresJava Closures
Java ClosuresBen Evans
 
Scala final ppt vinay
Scala final ppt vinayScala final ppt vinay
Scala final ppt vinayViplav Jain
 
A Tour Of Scala
A Tour Of ScalaA Tour Of Scala
A Tour Of Scalafanf42
 
The Rise of Functional Programming
The Rise of Functional ProgrammingThe Rise of Functional Programming
The Rise of Functional ProgrammingTjerk Wolterink
 
Introducing Scala to your Ruby/Java Shop : My experiences at IGN
Introducing Scala to your Ruby/Java Shop : My experiences at IGNIntroducing Scala to your Ruby/Java Shop : My experiences at IGN
Introducing Scala to your Ruby/Java Shop : My experiences at IGNManish Pandit
 
Scala Programming Introduction
Scala Programming IntroductionScala Programming Introduction
Scala Programming IntroductionairisData
 
Clojure in real life 17.10.2014
Clojure in real life 17.10.2014Clojure in real life 17.10.2014
Clojure in real life 17.10.2014Metosin Oy
 
Typesafe stack - Scala, Akka and Play
Typesafe stack - Scala, Akka and PlayTypesafe stack - Scala, Akka and Play
Typesafe stack - Scala, Akka and PlayLuka Zakrajšek
 
JSR 335 / java 8 - update reference
JSR 335 / java 8 - update referenceJSR 335 / java 8 - update reference
JSR 335 / java 8 - update referencesandeepji_choudhary
 
Unit 1 Core Java for Compter Science 3rd
Unit 1 Core Java for Compter Science 3rdUnit 1 Core Java for Compter Science 3rd
Unit 1 Core Java for Compter Science 3rdprat0ham
 
Spark - The Ultimate Scala Collections by Martin Odersky
Spark - The Ultimate Scala Collections by Martin OderskySpark - The Ultimate Scala Collections by Martin Odersky
Spark - The Ultimate Scala Collections by Martin OderskySpark Summit
 
Develop realtime web with Scala and Xitrum
Develop realtime web with Scala and XitrumDevelop realtime web with Scala and Xitrum
Develop realtime web with Scala and XitrumNgoc Dao
 
JAVA 8 Parallel Stream
JAVA 8 Parallel StreamJAVA 8 Parallel Stream
JAVA 8 Parallel StreamTengwen Wang
 
Lambda Expressions Java 8 Features usage
Lambda Expressions  Java 8 Features usageLambda Expressions  Java 8 Features usage
Lambda Expressions Java 8 Features usageAsmaShaikh478737
 
Introduction to Scala language
Introduction to Scala languageIntroduction to Scala language
Introduction to Scala languageAaqib Pervaiz
 
imperative programming language, java, android
imperative programming language, java, androidimperative programming language, java, android
imperative programming language, java, androidi i
 
Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)Martijn Verburg
 

Ähnlich wie 10+ new Java 8 features you need to know (20)

Java Closures
Java ClosuresJava Closures
Java Closures
 
Scala-Ls1
Scala-Ls1Scala-Ls1
Scala-Ls1
 
Scala final ppt vinay
Scala final ppt vinayScala final ppt vinay
Scala final ppt vinay
 
A Tour Of Scala
A Tour Of ScalaA Tour Of Scala
A Tour Of Scala
 
The Rise of Functional Programming
The Rise of Functional ProgrammingThe Rise of Functional Programming
The Rise of Functional Programming
 
Introducing Scala to your Ruby/Java Shop : My experiences at IGN
Introducing Scala to your Ruby/Java Shop : My experiences at IGNIntroducing Scala to your Ruby/Java Shop : My experiences at IGN
Introducing Scala to your Ruby/Java Shop : My experiences at IGN
 
Scala Programming Introduction
Scala Programming IntroductionScala Programming Introduction
Scala Programming Introduction
 
Clojure in real life 17.10.2014
Clojure in real life 17.10.2014Clojure in real life 17.10.2014
Clojure in real life 17.10.2014
 
Typesafe stack - Scala, Akka and Play
Typesafe stack - Scala, Akka and PlayTypesafe stack - Scala, Akka and Play
Typesafe stack - Scala, Akka and Play
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
JSR 335 / java 8 - update reference
JSR 335 / java 8 - update referenceJSR 335 / java 8 - update reference
JSR 335 / java 8 - update reference
 
Unit 1 Core Java for Compter Science 3rd
Unit 1 Core Java for Compter Science 3rdUnit 1 Core Java for Compter Science 3rd
Unit 1 Core Java for Compter Science 3rd
 
Spark - The Ultimate Scala Collections by Martin Odersky
Spark - The Ultimate Scala Collections by Martin OderskySpark - The Ultimate Scala Collections by Martin Odersky
Spark - The Ultimate Scala Collections by Martin Odersky
 
Develop realtime web with Scala and Xitrum
Develop realtime web with Scala and XitrumDevelop realtime web with Scala and Xitrum
Develop realtime web with Scala and Xitrum
 
JAVA 8 Parallel Stream
JAVA 8 Parallel StreamJAVA 8 Parallel Stream
JAVA 8 Parallel Stream
 
What’s new in java 8
What’s new in java 8What’s new in java 8
What’s new in java 8
 
Lambda Expressions Java 8 Features usage
Lambda Expressions  Java 8 Features usageLambda Expressions  Java 8 Features usage
Lambda Expressions Java 8 Features usage
 
Introduction to Scala language
Introduction to Scala languageIntroduction to Scala language
Introduction to Scala language
 
imperative programming language, java, android
imperative programming language, java, androidimperative programming language, java, android
imperative programming language, java, android
 
Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)
 

Mehr von Oleg Tsal-Tsalko

Developer on a mission (Devoxx UA 2021)
Developer on a mission (Devoxx UA 2021)Developer on a mission (Devoxx UA 2021)
Developer on a mission (Devoxx UA 2021)Oleg Tsal-Tsalko
 
From Streams to Reactive Streams
From Streams to Reactive StreamsFrom Streams to Reactive Streams
From Streams to Reactive StreamsOleg Tsal-Tsalko
 
JUG UA AdoptJSR participation
JUG UA AdoptJSR participationJUG UA AdoptJSR participation
JUG UA AdoptJSR participationOleg Tsal-Tsalko
 
Develop modern apps using Spring ecosystem at time of BigData
Develop modern apps using Spring ecosystem at time of BigData Develop modern apps using Spring ecosystem at time of BigData
Develop modern apps using Spring ecosystem at time of BigData Oleg Tsal-Tsalko
 
Java 8 date & time javaday2014
Java 8 date & time javaday2014Java 8 date & time javaday2014
Java 8 date & time javaday2014Oleg Tsal-Tsalko
 
Enterprise Integration Patterns
Enterprise Integration PatternsEnterprise Integration Patterns
Enterprise Integration PatternsOleg Tsal-Tsalko
 
Distributed systems and scalability rules
Distributed systems and scalability rulesDistributed systems and scalability rules
Distributed systems and scalability rulesOleg Tsal-Tsalko
 
JUG involvment in JCP and AdopJSR program
JUG involvment in JCP and AdopJSR programJUG involvment in JCP and AdopJSR program
JUG involvment in JCP and AdopJSR programOleg Tsal-Tsalko
 

Mehr von Oleg Tsal-Tsalko (14)

Developer on a mission (Devoxx UA 2021)
Developer on a mission (Devoxx UA 2021)Developer on a mission (Devoxx UA 2021)
Developer on a mission (Devoxx UA 2021)
 
Developer on a mission
Developer on a missionDeveloper on a mission
Developer on a mission
 
From Streams to Reactive Streams
From Streams to Reactive StreamsFrom Streams to Reactive Streams
From Streams to Reactive Streams
 
Java 9 Jigsaw HackDay
Java 9 Jigsaw HackDayJava 9 Jigsaw HackDay
Java 9 Jigsaw HackDay
 
JUG UA AdoptJSR participation
JUG UA AdoptJSR participationJUG UA AdoptJSR participation
JUG UA AdoptJSR participation
 
Develop modern apps using Spring ecosystem at time of BigData
Develop modern apps using Spring ecosystem at time of BigData Develop modern apps using Spring ecosystem at time of BigData
Develop modern apps using Spring ecosystem at time of BigData
 
Lambdas HOL
Lambdas HOLLambdas HOL
Lambdas HOL
 
Java 8 date & time javaday2014
Java 8 date & time javaday2014Java 8 date & time javaday2014
Java 8 date & time javaday2014
 
Java 8 date & time
Java 8 date & timeJava 8 date & time
Java 8 date & time
 
Get ready for spring 4
Get ready for spring 4Get ready for spring 4
Get ready for spring 4
 
Enterprise Integration Patterns
Enterprise Integration PatternsEnterprise Integration Patterns
Enterprise Integration Patterns
 
Distributed systems and scalability rules
Distributed systems and scalability rulesDistributed systems and scalability rules
Distributed systems and scalability rules
 
Next stop: Spring 4
Next stop: Spring 4Next stop: Spring 4
Next stop: Spring 4
 
JUG involvment in JCP and AdopJSR program
JUG involvment in JCP and AdopJSR programJUG involvment in JCP and AdopJSR program
JUG involvment in JCP and AdopJSR program
 

Kürzlich hochgeladen

UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college projectTonystark477637
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...RajaP95
 

Kürzlich hochgeladen (20)

UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
 

10+ new Java 8 features you need to know

  • 1. 10+ new features you ought to know using Java 8 Oleg Tsal-Tsalko JavaDay Lviv 2015
  • 2. LEAD SOFTWARE ENGINEER AT EPAM SYSTEMS. PATIONATE DEVELOPER, SPEAKER, ACTIVE MEMBER OF KIEV JUG. PARTICIPATE IN DIFFERENT EDUCATIONAL INITIATIVES, ENGINEERING EVENTS AND JCP/ADOPTJSR PROGRAMS. OLEG TSAL-TSALKO ABOUT ME
  • 3. 3CONFIDENTIAL •  Stream API •  Lambdas and method references •  Default methods •  Optional values •  Date & Time API •  Stamped Locks and Concurrent Adders •  Type annotations and repeated annotations •  New files operations •  Overflow operations and Base64 encoding •  Nashorn JavaScript engine Agenda
  • 4. 4CONFIDENTIAL •  An abstraction that supports bulk operations over sequence of elements •  Not a data structure •  Simple and logical chaining of operations •  Lazy evaluation •  Internal parallelism if required •  Concept of functional programming in Java #1 Stream API
  • 5. 5CONFIDENTIAL •  Collection.stream() •  IntStream.range() •  Stream.of() •  Arrays.stream() •  BufferedReader.lines() •  CharSequence.chars() •  Pattern.splitAsStream() How can I get a Stream?
  • 6. 6CONFIDENTIAL Fluent and simple txns.stream() .filter(t ->t.getBuyer().getAge()>=65) .map(Txn::getSeller) .distinct() .sort(comparing(Seller::getName)) .forEach(s -> System.out.println(s.getName());
  • 7. 7CONFIDENTIAL java.util.function Package: Predicate<T> Determine if the input of type T matches some criteria Consumer<T> Accept a single input argument of type T, and return no result Function<T, R> Apply a function to the input type T, generating a result of type R java.util.stream Package: Collector<T, A, R> Used to collect stream of elements of type T into single result of type R Collectors Contains number of predefined Collectors Functional interfaces
  • 8. 8CONFIDENTIAL A lambda expression is an anonymous function –  Argument list, a return type, and a body (Object o) -> o.toString() –  Method reference Object::toString –  Capture value from enclosing context (Person p) ->p.getName().equals(name) –  Type inference p -> p.getName().equals(name) –  Forget to use anonymous classes You can now pass behavior as a data between your objects #2 Lambdas
  • 9. 9CONFIDENTIAL #3 Method reference FileFilter x = (File f) -> f.canRead(); FileFilter x = File::canRead; FileFilter x = new FileFilter() { public boolean accept(File f) { return f.canRead(); } };
  • 10. 10CONFIDENTIAL Since Java doesn’t have Function type on it’s own Lambda’s type evaluated to some Functional interface: Runnable r = () -> { doSmth(); }; Callable c = () -> calcResult(); Comparator comp = (o1, o2) -> compare(o1, o2); What’s your type?
  • 11. 11CONFIDENTIAL Influence on existing classes java.lang.Iterable#forEach() java.util.Collection#stream() java.util.Collection#parallelStream() java.util.Comparator#comparing(…) java.util.Comparator#thenComparing(…) java.util.Comparator#reverse() …
  • 12. 12CONFIDENTIAL SHOW ME THE CODE Lambdas and streams TALK IS CHEAP
  • 13. 13CONFIDENTIAL •  Libraries need to evolve, or they stagnate •  Java preserves compatibility •  Multiple inheritance in Java? •  Default methods can reduce implementation burden •  Resolution rules: – Class wins over interface – More specific subclass wins – No 3rd rule #4 Default methods
  • 14. 14CONFIDENTIAL •  Annoyed by NPEs? •  Should your method return null or throw RuntimeException? •  Wondering how to implement SpecialCase pattern? •  Inspired by functional programming and want to build a method chain for NULL handling? => You are lucky with Java 8… #5 Optional
  • 15. 15CONFIDENTIAL #6 Date & Time API •  Replaces old ambiguous java.util.Date, Calendar, TimeZone, DateFormat classes with lots of deprecations •  More fluent/simple/clean API •  Immutable classes •  Using Java8 features including lambdas •  Precise separation of concepts
  • 16. 16CONFIDENTIAL •  LocalDate – a date only •  LocalTime – a time only •  LocalDateTime – date with time •  ZonedDateTime – date with time in time zone •  Period - date-based amount of time •  Duration - time-based amount of time •  And more… Range of types
  • 17. 17CONFIDENTIAL Time Zones If you can avoid using TimeZones – do it! If not – use ZonedDateAndTime!
  • 18. 18CONFIDENTIAL •  ZoneId – replacement for TimeZone class (e.g. “Europe/London”, “Europe/Kiev”) •  ZoneOffset – representing offset from UTC time •  ZoneRules – behind the scenes class which defines time zone rules •  ZonedDateTime – main date/time class which is aware of time zones TimeZone classes in Java 8
  • 19. 19CONFIDENTIAL New API is very flexible because it based on number of abstractions at it’s bottom: Temporal – parent class for all date/time objects which defines mutation operation for them such as plus/minus/ with TemporalAdjuster – functional interface which responsible for mutating Temporal objects TemporalField – represents parts/fields of date/time objects such as (DAY_OF_WEEK, MONTH, etc.) TemporalUnit – represents type of date/time values such as (MINUTES, DAYS, YEARS, etc.) TemporalAmount – class which represents amount of time Power of abstraction
  • 20. 20CONFIDENTIAL SHOW ME THE CODE Optional and Date and Time API TALK IS CHEAP
  • 21. 21CONFIDENTIAL •  Whenever we think of using RWLock •  RWLock can cause starvation of readers •  RWLock is pessimistic on reads •  Read lock is optimistic •  Optimistic lock can be converted to pessimistic lock if necessary •  Write locks are always pessimistic #7 StampedLock
  • 22. 22CONFIDENTIAL •  [Java 5] When readers are given priority, then writers might never be able to complete •  [Java 6] But when writers are given priority, readers might be starved ⇒ In Java 8 use StampedLock instead! RWLock starvation
  • 23. 23CONFIDENTIAL •  Pros – Has much better performance than ReentrantReadWriteLock – Latest versions do not suffer from starvation of writers •  Cons – Idioms are more difficult to get right than with ReadWriteLock – A small difference can make a big difference in performance StampedLock
  • 24. 24CONFIDENTIAL How would you implement counter in multithreaded environment? •  Dirty counters (silly) •  Synchronized (very slow) •  RWLock (slow) •  Volatile (only if you have 1 writer/updater) •  AtomicInteger (yes, before Java 8…) ⇒  LongAdder in Java 8! #8 Concurrent Adders
  • 26. 26CONFIDENTIAL 9 Improved annotations 10 New file operations 11 Overflow operations 12 Base64 encoding 13 Nashorn JavaScript engine
  • 27. 27CONFIDENTIAL •  Process Termination •  Strong Random Generation •  Date.toInstant() •  Interface static methods •  Better Type Inference •  Parameter names support by compiler •  Parallel Arrays •  Nashorn CLI JavaScript interpriter •  Class dependency analyzer However there are even more…
  • 28. 28CONFIDENTIAL •  https://www.google.com/?gws_rd=ssl •  https://github.com/RichardWarburton/java-8- lambdas-exercises •  http://javaspecialists.eu/talks/jfokus13/ PhaserAndStampedLock.pdf •  http://www.javacodegeeks.com/2014/05/ java-8-features-tutorial.html •  http://blog.takipi.com/10-features-in-java-8- you-havent-heard-of/ Resources