2. ABOUT ME Rajmahendra Hegde (Raj)
• Working for ValueLabs as Scrum Master/Project
Lead
• 14 years Java development
• JUG Hyderabad Lead
• NetBeans Dream Team Member
• JCP Individual and Expert Group Member for 3
JSRs
• Comitter / Contributor: JBake, Forge, NetBeans,
eWidgetFX, JavaFX, Gradle, Agorava, JRebirth,
ScalaFX
Twitter: @rajonjava
GitHub: rajmahendra
LinkedIn: rajmahendra
5. JAVA LAMBDA
Beginning of Functional flavor into Java platform
Lambda provides anonymous function to Java
Replaces the old use of Anonymous inner classes
Write more compact code
Parallel programming easier
9. LAMBDA & FUNCTIONAL INTERFACE
Functional interface are interface with only one
method.
Java space is filled of such Interfaces
java.lang.Runnable.run();
java.util.Comparator.compare(T a, Tb);
java.awt.event.ActionListener.actionPerformed(
ActionEvent e)
10. JAVA8 LAMBDA PACKAGE
Additionally Java8 also provides
FunctionalInterface in package java.util.function to
use with Lambdas. This package contains more
than 40 commonly used FI
Predicate<T>.test(T t) - Represents a predicate
(boolean-valued function) of one argument
Consumer<T>.accept(T t) - Represents an operation
that accepts a single input argument and returns no
result
Function<T, R>.R accept(T t) - Represents a function
that accepts one argument and produces a result
Supplier<T>. T get() -Represents a supplier of results
…
11. @FUNCTIONALINTERFACE
FunctionalInterface = Interface with only one
method
Annotation is optional. Its only to make sure the
interface is a FunctionalInterface
Any interface with only one method can be
considered as FunctionalInterface
13. VARIABLE CAPTURE
Lambda can interact with the variable outside of its
body
Using the variables outside of the Lambda
expression is called Variable Capture
Effectively final
14. LAMBDA VS ANONYMOUS INNER CLASS
Lambda != Anonymous Inner Class
Inner class can have state
Inner class can have multiple methods
this points to the object instance in a inner class
but points to the enclosed object in Lambda
Lambda != Anonymous Inner Class
15. METHOD REFERENCE
Use method reference when you use Lambda
expression
Reduces boilerplate code
NOTE: return type of lambda expression must
match with the signature of the referred method
17. DEFAULT METHOD - INTERFACE
Provides a way to add new methods to interface
without breaking the old implementation
default keyword is introduced to do this magic
18. NO MORE NULLPOINTEREXCEPTION !
Wrapper class to guard from Null Exception
java.util.Optional<T>
It contain a data or a empty
20. STREAMS
Streams are functional programming design pattern
Helps in processing sequential elements as
sequentially or parallel
In java we use in many different places
Retrieve database query as list objects
Iterate over xml or json elements
Read multiple lines
Collections, map etc.
21. STREAMS IN JAVA
To create a stream you use a Source collection
Add a filter option to the stream Intermediate
operation pipeline
And ends with Terminal operation which starts the
stream process
22. STREAM LIFECYCLE
Creation – Stream is created with the collection
object from source
Configure – get configured with the list of pipeline
operators
Execution – Streams Terminal operation triggers
the stream to starts by pulling objects into the
pipeline
Cleanup
24. OLD DATE/TIME API
java.util.Date
java.sql.Date
java.util.Calendar
java.util.GregorianCalendar
java.util.TimeZone
java.text.DateFormat
java.text.SimpleDateFormat
25. ISSUES WITH OLD API
All are just utility class (in java.util package or in
java.text)
Date class contains both Date and Time
Different Date class for SQL!
Date doesn't have timezone
Month is zero based, year is 1900 based.
Not thread safe by default
Arithmetic operations are hard to use
26. DATE AND TIME API
New dedicated date time package java.time
Dedicated class for Date and time LocalDate and
LocalTime
A composite class for both LocalDateTime
Numerous way to create Date time objects
Support for Truncation, TimeZones, Periods,
Durations and Chronologies
More fluent, clean and simple API
Immutable classes
30. TIMEZONE
Numerous timezones are available
Some time complex to manipulate
Some time it may change frequently
TimeZone Classes
ZoneId – Europe/London etc.
ZoneOffset – offset from UTC time
ZoneRules – defines timezone rules
ZonedDateTime – TimeZone aware Datetime class
34. NASHORN
Nashorn is a JavaScript Engine developed on Java
Light-weight, high-performance integrated into JRE
ECMAScript-262 Edition 5.1 language specification
compliance
Java 8 shipped with a command-line tool called jjs
JDK 6 already shipped with Mozilla’s Rhino
JavaScript Engine.