SlideShare una empresa de Scribd logo
1 de 87
Descargar para leer sin conexión
Java SE 8 Library Design
Using the new features well
Stephen Colebourne
Engineering Lead, OpenGamma
October 2016
Stephen Colebourne
● Java Champion, regular conference speaker
● Best known for date & time - Joda-Time and JSR-310
● More Joda projects - http://www.joda.org
● Major contributions in Apache Commons
● Blog - http://blog.joda.org
● Worked at OpenGamma for 6 years
Strata, from OpenGamma
● Open Source market risk library
● Valuation and risk calcs for finance
○ interest rate swap, FRA, CDS
● Great example of Java SE 8 coding style
http://strata.opengamma.io/
Introduction
⇒
Introduction
● Java SE 8 is a major update to Java
● Major new features
○ Lambdas
○ Streams
○ Methods on interfaces
○ Date and Time
Introduction
● Essential to rethink how you code
● Reconsider coding conventions
● Appreciate new design options
Agenda
● Lambdas
● Streams
● Design with Lambdas
● Abstraction
● Immutability
● Interfaces
● Optional
● Odds and Ends
Lambdas
λ
Lambdas
● Block of code
○ like an anonymous inner class
● Always assigned to a Functional Interface
○ an interface with one abstract method
○ Runnable, Callable, Comparator
● Uses target typing
○ context determines type of the lambda
// Java 7
List<Person> people = loadPeople();
Collections.sort(people, new Comparator<Person>() {
@Override
public int compare(Person p1, Person p2) {
return p1.name.compareTo(p2.name);
}
});
Lambdas
public interface Comparator<T> {
int compare(T obj1, T obj2);
}
// Java 7
Collections.sort(people, new Comparator<Person>() {
@Override
public int compare(Person p1, Person p2) {
return p1.name.compareTo(p2.name);
}
});
// Java 7
List<Person> people = loadPeople();
Collections.sort(people, new Comparator<Person>() {
@Override
public int compare(Person p1, Person p2) {
return p1.name.compareTo(p2.name);
}
});
Lambdas
public interface Comparator<T> {
int compare(T obj1, T obj2);
}
// Java 7
Collections.sort(people, new Comparator<Person>() {
@Override
public int compare(Person p1, Person p2) {
return p1.name.compareTo(p2.name);
}
});
// Java 7
List<Person> people = loadPeople();
Collections.sort(people, new Comparator<Person>() {
@Override
public int compare(Person p1, Person p2) {
return p1.name.compareTo(p2.name);
}
});
Lambdas
public interface Comparator<T> {
int compare(T obj1, T obj2);
}
// Java 8
people.sort((p1, p2) -> p1.name.compareTo(p2.name));
Top tips for Lambdas
● Use lambdas wherever appropriate
● Mostly, they just work
● Sometimes, the compiler needs a hint
○ use local variable
○ add the type to the lambda parameter
Lambdas
Lambdas affect code
but do they affect design?
Streams
♒
Streams
● Many loops have a similar "shape"
● Repetitive design patterns
● Stream library provides a way to abstract this
● Lambdas used to pass the interesting bits
Streams
List<Trade> trades = loadTrades();
List<Money> valued = new ArrayList<>();
for (Trade t : trades) {
if (t.isActive()) {
Money pv = t.presentValue();
valued.add(pv);
}
}
Streams
List<Trade> trades = loadTrades();
List<Money> valued = new ArrayList<>();
for (Trade t : trades) {
if (t.isActive()) {
Money pv = t.presentValue();
valued.add(pv);
}
}
Streams
List<Trade> trades = loadTrades();
List<Money> valued =
trades.stream()
.filter(t -> t.isActive())
.map(t -> t.presentValue())
.collect(Collectors.toList());
Streams
● New stream() method on Collection
● Sequence of operations on underlying data
● Logic passed in using a lambda
○ filter() to retain/remove
○ map() to change
○ reduce() to summarise
○ sorted() to sort using a comparator
Streams
trades.stream()
.filter(t -> t.isActive())
.map(t -> t.presentValue())
.collect(Collectors.toList());
Streams
trades.stream()
.filter(new Predicate<Trade>() {
public boolean test(Trade t) {
return t.isActive();
}
})
.map(new Function<Trade, Money>() {
public Money apply(Trade t) {
return t.presentValue();
}
})
.collect(Collectors.toList());
Streams
Stream API not practical
without lambdas
Exceptions in Streams
● For-each loop is a language feature
● Streams are implemented using regular methods
● Big difference in stack traces
Exceptions in Streams
java.lang.IllegalArgumentException: Oops
at com.opengamma.strata.calc.DefaultCalculationRunner.lambda$2(DefaultCalculationRunner.java:98)
at java.util.stream.ReferencePipeline$11$1.accept(ReferencePipeline.java:372)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.Iterator.forEachRemaining(Iterator.java:116)
at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
at com.opengamma.strata.calc.DefaultCalculationRunner.calculate(DefaultCalculationRunner.java:100)
at com.opengamma.strata.calc.DefaultCalculationRunner.lambda$0(DefaultCalculationRunner.java:86)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.Iterator.forEachRemaining(Iterator.java:116)
at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
at com.opengamma.strata.calc.DefaultCalculationRunner.calculate(DefaultCalculationRunner.java:87)
at com.opengamma.strata.calc.DefaultCalculationRunnerTest.calculate(DefaultCalculationRunnerTest.java:49)
Stack trace of
inner stream
Stack trace of
outer stream
Exceptions in Streams
java.lang.IllegalArgumentException: Oops
at com.opengamma.strata.calc.DefaultCalculationRunner.calculate(DefaultCalculationRunner.java:102)
at com.opengamma.strata.calc.DefaultCalculationRunner.calculate(DefaultCalculationRunner.java:87)
at com.opengamma.strata.calc.DefaultCalculationRunnerTest.calculate(DefaultCalculationRunnerTest.java:49)
Stack trace of
for-each loop
Top tips for streams
● Stream not always more readable than loop
● Stream exceptions can be much worse
● My advice:
○ use streams for small, localized, pieces of logic
○ be cautious using streams for large scale logic
● Strata uses for-each loops at top level
○ solely for shorter stack traces
Design with Lambdas
Design with Lambdas
● Lambda is converted to a functional interface
● Normal interface with one abstract method
● Java SE 8 adds many new functional interfaces
○ Function<T, R>
○ Predicate<T>
○ Supplier<T>
○ Consumer<T>
○ see java.util.function package
● Primitive versions only for long, int, double
Functional interfaces
● Learn the standard functional interfaces
● Only create new ones if adding additional value
○ lots of parameters
○ mix of primitive and object parameters
○ feature really needs a good name or Javadoc
Functional interface example
// API functional interface
@FunctionalInterface
public interface Perturbation {
public abstract double perturb(int index, double value);
}
// API method that can be used by a lambda
public Curve perturbed(Perturbation perturbation) { … }
// caller code
curve = curve.perturbed((i, v) -> v + 1e-4);
Functional interface example
// API functional interface
@FunctionalInterface
public interface Perturbation {
public abstract double perturb(int index, double value);
}
// API method that can be used by a lambda
public Curve perturbed(Perturbation perturbation) { … }
// caller code
curve = curve.perturbed((i, v) -> v + 1e-4);
Name has meaning
Method signature is complex
Time-series example
● A time-series stores changes to a value over time
● Date-based one like Map<LocalDate, Double>
● What if you want to change the values?
Time-series example
// API method that can be used by a lambda
public LocalDateDoubleTimeSeries
mapValues(DoubleUnaryOperator mapper){ … }
// caller code
ts = ts.mapValues(v -> v * 2);
Time-series example
// API method that can be used by a lambda
public LocalDateDoubleTimeSeries
mapValues(DoubleUnaryOperator mapper){ … }
// caller code
ts = ts.mapValues(v -> v * 2);
Multiplication - no need for
multipliedBy(double)
on the API
Time-series example
// API method that can be used by a lambda
public LocalDateDoubleTimeSeries
mapValues(DoubleUnaryOperator mapper){ … }
// caller code
ts = ts.mapValues(v -> v * 2);
ts = ts.mapValues(v -> v / 4);
Multiplication - no need for
multipliedBy(double)
on the API
Division - no need for
dividedBy(double)
on the API
Design with Lambdas
Method taking a lambda
can be more flexible design
Abstraction with Lambdas
✯
Abstraction
● Two or more classes with the same methods
● Abstract using an interface?
● Lambdas provide an alternative
● Consider an example with static methods
○ no way to abstract that with interfaces...
Abstraction
// standard API producing results
public static Money pv(FraTrade trade, Market md) { … }
public static Sens pv01(FraTrade trade, Market md) { … }
public static Double par(FraTrade trade, Market md) { … }
Abstraction
// standard API producing results
public static Money pv(FraTrade trade, Market md) { … }
public static Sens pv01(FraTrade trade, Market md) { … }
public static Double par(FraTrade trade, Market md) { … }
// functional interface matching all three methods
interface Calc<T> {
public abstract T invoke(FraTrade trade, Market market);
}
Abstraction
// create abstraction to access method by "measure" key
Map<Measure, Calc> CALCS = ImmutableMap.builder()
.put(Measures.PRESENT_VALUE, FraCalcs::pv)
.put(Measures.PV01, FraCalcs::pv01)
.put(Measures.PAR_RATE, FraCalcs:: par)
.build();
// can now invoke using measure
return CALCS.get(measure).invoke(trade, market);
Abstraction
● Class being abstracted was not changed
● Provides way to abstract over code you do not own
● Less need for reflection
Design with Lambdas
Lambdas can abstract
in dynamic/flexible ways
Immutability
Multi-threaded
● JDK provides many tools for concurrency
● Parallel streams makes it even easier
● But parallel code is not simple to get right
Thread problems
● What if trade modified by some other piece of code?
● Check-then-act bug
List<Trade> trades = loadTrades();
List<Money> valued =
trades.stream()
.filter(t -> t.isActive())
.map(t -> presentValue(t))
.collect(Collectors.toList());
Check
then Act
Immutable
● Threading bugs due to shared mutable state
● One solution is to use immutable beans
● No possibility of check-then-act type bug
Immutable beans
● Class should be final
○ no subclasses
● Fields must be final
○ needed for Java Memory Model
● Field types should be immutable
○ eg. don't use java.util.Date
● Factory methods and Builders instead of constructors
Immutable beans
● IDEs help you write mutable beans
● Need better tooling for immutable beans
○ AutoValue
○ Immutables.org
○ Joda-Beans
● Strata uses Joda-Beans
http://www.joda.org/joda-beans
Joda-Beans
@BeanDefinition
public final TradeInfo implements ImmutableBean {
/** The trade identifier. */
@PropertyDefinition(validate = "notNull")
private final StandardId tradeId;
/** The trade date. */
@PropertyDefinition(validate = "notNull")
private final LocalDate tradeDate;
}
Joda-Beans
● Source code generated for
○ getters
○ builder
○ equals/hashCode/toString
○ properties - like C#
● Can add your own code to the class and still regenerate
● Built in XML, JSON and Binary serialization
Immutable beans
● Most systems better using immutability everywhere
● Java SE 8 parallelStream() pushes at this
● Threading issues mostly eliminated
● No class hierarchies, use interfaces
Use interfaces
Trade
ProductTrade ResolvableTrade
SwapTrade FraTrade
Resolved
SwapTrade
Resolved
FraTrade
Use interfaces
● Concrete classes with no hierarchies
● Interfaces provide the hierarchy
● Methods on interfaces make this practical
● All implementations of interface should be immutable
○ "Implementations must be immutable and thread-safe beans."
● Strata uses immutable beans everywhere
Immutability
It is time to move on
from mutable data objects
Interfaces
I
Interfaces
● Two changes to interfaces
● Default methods
○ normal method, but on an interface
○ cannot default equals/hashCode/toString
● Static methods
○ normal static method, but on an interface
Coding Style
● Use modifiers in interfaces
● Much clearer now there are different types of method
● Prepares for private methods in Java SE 9
public interface Foo {
public static of(String id) { … }
public abstract isEmpty();
public default isNotEmpty() { … }
}
Interfaces
● Methods on interfaces changes design
● Interfaces are part of macro-design
○ lambdas and streams affect micro-design
● Strata uses default and static methods liberally
Holiday Calendar
● Strata interface to specify which days are holidays
public interface HolidayCalendar {
// a normal abstract interface method
public abstract isHoliday(LocalDate date);
…
}
Holiday Calendar
● Default methods make the interface more useful
public interface HolidayCalendar {
public abstract isHoliday(LocalDate date);
// check if date is a business day
public default isBusinessDay(LocalDate date) {
return !isHoliday(date);
}
}
Holiday Calendar
● Default methods make the interface more useful
public interface HolidayCalendar {
public abstract isHoliday(LocalDate date);
// find the next business day
public default next(LocalDate date) {
LocalDate nextDay = date.plusDays(1);
return isHoliday(nextDay) ? next(nextDay) : nextDay;
}
}
Holiday Calendar
● Static methods avoid HolidayCalendarFactory
public interface HolidayCalendar {
// find holiday calendar by identifier such as DKCO
public static of(String id) {
// lookup calendar
}
}
Holiday Calendar
● Interface used just as would be expected
// find holiday calendar by identifier such as DKCO
HolidayCalendar cal = HolidayCalendar.of("DKCO");
// use calendar to select the trade start date
LocalDate startDate = cal.next(tradeDate);
Interfaces
● Interface now acts as abstract class
○ Only need abstract class if need abstracted state
○ but abstracted state is generally a bad idea
● Interface can now acts as a factory
○ Not suitable for all factory use cases*
* In Strata, holiday calendars are not really fixed at startup, but it made a good example for this talk!
Package-scoped implementation
● Can the interface be the only public API?
● Can the implementation class be package-scoped?
● Strata uses this pattern a lot
Interfaces
Consider package-scoped
factory and implementation
Optional and null
?
Optional and null
● New class Optional added to Java 8
● Opinions are polarized
○ some think it is the saviour of the universe
○ others think it is useless
● Used pragmatically, can be very useful
Optional and null
● Simple concept - two states
○ present, with a value - Optional.of(foo)
○ empty - Optional.empty()
Optional and null
● Standard code using null
// library, returns null if not found
public Foo getValue(String key) { … }
// application code must remember to check for null
Foo foo = getValue(key);
if (foo == null) {
foo = Foo.DEFAULT; // or throw an exception
}
Optional and null
● Standard code using Optional
// library, returns Optional if not found
public Optional<Foo> findValue(String key) { … }
// application code
Foo foo = findValue(key).orElse(Foo.DEFAULT);
// or
Foo foo = findValue(key).orElseThrow( … );
Optional and null
● Important that a variable of type Optional is never null
● Prefer methods like map() and orElse()
● Minimise use of isPresent()
Optional
● Strata often uses set of 3-methods
public abstract Optional<T> findValue(DataId<T> id);
public default boolean containsValue(DataId<T> id) {
return findValue(id).isPresent();
}
public default T getValue(DataId<T> id) {
return findValue(id).orElseThrow(
() -> new MarketDataException());
}
Optional
● Optional is a class
● Some memory/performance cost to using it
● Not serializable
● Not ideal to be an instance variable
● JDK authors added it for return types
● Use in parameters often annoying for callers
● Use as return type gets best value from concept
http://blog.joda.org/2015/08/java-se-8-optional-pragmatic-approach.html
Optional in Strata
● Strata has no exposed nulls
● No part of the API will return null
● Optional used when something is optional
● Pragmatically, null is used within classes
Optional
Use Optional in a
pragmatic way
Odds and Ends
Java SE 8 version
● Use Java SE 8 update 40 or later
○ preferably use the latest available
● Earlier versions have annoying lambda/javac issues
Internal JDK packages
● Java SE 9 will remove access to some JDK packages
○ sun.*
○ com.sun.*
○ com.oracle.*
● Now is the time to prepare for this
○ Avoid sun.misc.Unsafe
○ Stick to the standard JDK API
Parameters
● Java SE 8 can reflect on parameter names
● Avoids need for additional libraries like paranamer
● Not enabled by default, must choose to include data
Checked exceptions
● Checked exceptions can be made to disappear
● Helper methods can convert to runtime exceptions
Unchecked.wrap(() -> {
// any code that might throw a checked exception
// converted to a runtime exception
});
Summary
J8
Summary
● Lots of good stuff in Java SE 8
● Design and coding standards change
● Lots more potential to abstract, but don't over-use
● Methods on interfaces add a lot of power
Key Strata design features
● Immutable data objects, using Joda-Beans
● Static methods on interfaces, package-scope impls
● Make use of new abstractions
● Beware stack traces with streams
● Pragmatic use of Optional, null never returned from API
Work in Finance?
● Take a look at OpenGamma Strata
○ developed from the ground up in Java 8
○ lots of good Java 8 techniques and utilities
● High quality library for market risk
○ day counts, schedules, holidays, indices
○ models and pricing for swaps, FRAs, swaptions, FX, futures…
○ open source and stable release v1.1
http://strata.opengamma.io/

Más contenido relacionado

La actualidad más candente

New Features in JDK 8
New Features in JDK 8New Features in JDK 8
New Features in JDK 8Martin Toshev
 
Introduction of Java 8 with emphasis on Lambda Expressions and Streams
Introduction of Java 8 with emphasis on Lambda Expressions and StreamsIntroduction of Java 8 with emphasis on Lambda Expressions and Streams
Introduction of Java 8 with emphasis on Lambda Expressions and StreamsEmiel Paasschens
 
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
 
Improved Developer Productivity In JDK8
Improved Developer Productivity In JDK8Improved Developer Productivity In JDK8
Improved Developer Productivity In JDK8Simon Ritter
 
Java SE 8 - New Features
Java SE 8 - New FeaturesJava SE 8 - New Features
Java SE 8 - New FeaturesNaveen Hegde
 
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 JavaSimon Ritter
 
New Features Of JDK 7
New Features Of JDK 7New Features Of JDK 7
New Features Of JDK 7Deniz Oguz
 
Lambdas : Beyond The Basics
Lambdas : Beyond The BasicsLambdas : Beyond The Basics
Lambdas : Beyond The BasicsSimon Ritter
 
10 Sets of Best Practices for Java 8
10 Sets of Best Practices for Java 810 Sets of Best Practices for Java 8
10 Sets of Best Practices for Java 8Garth Gilmour
 
java 8 new features
java 8 new features java 8 new features
java 8 new features Rohit Verma
 
Lambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon Ritter
Lambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon RitterLambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon Ritter
Lambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon RitterJAXLondon2014
 
Project Jigsaw in JDK9
Project Jigsaw in JDK9Project Jigsaw in JDK9
Project Jigsaw in JDK9Simon Ritter
 
Java 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & StreamsJava 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & StreamsNewCircle Training
 

La actualidad más candente (20)

Java 8 Features
Java 8 FeaturesJava 8 Features
Java 8 Features
 
New Features in JDK 8
New Features in JDK 8New Features in JDK 8
New Features in JDK 8
 
Introduction of Java 8 with emphasis on Lambda Expressions and Streams
Introduction of Java 8 with emphasis on Lambda Expressions and StreamsIntroduction of Java 8 with emphasis on Lambda Expressions and Streams
Introduction of Java 8 with emphasis on Lambda Expressions and Streams
 
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)
 
Improved Developer Productivity In JDK8
Improved Developer Productivity In JDK8Improved Developer Productivity In JDK8
Improved Developer Productivity In JDK8
 
Java 8 Feature Preview
Java 8 Feature PreviewJava 8 Feature Preview
Java 8 Feature Preview
 
Java SE 8 - New Features
Java SE 8 - New FeaturesJava SE 8 - New Features
Java SE 8 - New Features
 
Code generating beans in Java
Code generating beans in JavaCode generating beans in Java
Code generating beans in Java
 
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
 
New Features Of JDK 7
New Features Of JDK 7New Features Of JDK 7
New Features Of JDK 7
 
Lambdas : Beyond The Basics
Lambdas : Beyond The BasicsLambdas : Beyond The Basics
Lambdas : Beyond The Basics
 
Java 8 ​and ​Best Practices
Java 8 ​and ​Best PracticesJava 8 ​and ​Best Practices
Java 8 ​and ​Best Practices
 
10 Sets of Best Practices for Java 8
10 Sets of Best Practices for Java 810 Sets of Best Practices for Java 8
10 Sets of Best Practices for Java 8
 
java 8 new features
java 8 new features java 8 new features
java 8 new features
 
Java 8 features
Java 8 featuresJava 8 features
Java 8 features
 
Java 8 Lambda and Streams
Java 8 Lambda and StreamsJava 8 Lambda and Streams
Java 8 Lambda and Streams
 
Lambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon Ritter
Lambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon RitterLambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon Ritter
Lambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon Ritter
 
Project Jigsaw in JDK9
Project Jigsaw in JDK9Project Jigsaw in JDK9
Project Jigsaw in JDK9
 
Java 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & StreamsJava 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & Streams
 
Java 8 by example!
Java 8 by example!Java 8 by example!
Java 8 by example!
 

Destacado

Code Review Matters and Manners
Code Review Matters and MannersCode Review Matters and Manners
Code Review Matters and MannersTrisha Gee
 
[Suriano & Perry] [Library Design: Community Transformation] IFLA LBES 2016
[Suriano & Perry] [Library Design: Community Transformation] IFLA LBES 2016[Suriano & Perry] [Library Design: Community Transformation] IFLA LBES 2016
[Suriano & Perry] [Library Design: Community Transformation] IFLA LBES 2016Diane Koen
 
Peckham Library Case Study
Peckham Library Case StudyPeckham Library Case Study
Peckham Library Case StudyFatima Akbar
 
ARCHITECTURAL STANDARDS
ARCHITECTURAL STANDARDSARCHITECTURAL STANDARDS
ARCHITECTURAL STANDARDSstuti31
 
Library Design and Architecture - 2012
Library Design and Architecture - 2012Library Design and Architecture - 2012
Library Design and Architecture - 2012Moreno Barros
 
Is Groovy better for testing than Java?
Is Groovy better for testing than Java?Is Groovy better for testing than Java?
Is Groovy better for testing than Java?Trisha Gee
 
Hanna Springs Sculpture Garden
Hanna Springs Sculpture GardenHanna Springs Sculpture Garden
Hanna Springs Sculpture GardenNancy Gray
 
Space Solutions in Makerspaces at Darien Library
Space Solutions in Makerspaces at Darien LibrarySpace Solutions in Makerspaces at Darien Library
Space Solutions in Makerspaces at Darien LibraryAmanda L. Goodman
 
PAARL Standards for Academic Libraries 2010 (Final Draft Proposal)
PAARL Standards for Academic Libraries 2010 (Final Draft Proposal)PAARL Standards for Academic Libraries 2010 (Final Draft Proposal)
PAARL Standards for Academic Libraries 2010 (Final Draft Proposal)Fe Angela Verzosa
 
Library Design for the 21st Century Learner: CEFPI Southern Region
Library Design for the 21st Century Learner:  CEFPI Southern RegionLibrary Design for the 21st Century Learner:  CEFPI Southern Region
Library Design for the 21st Century Learner: CEFPI Southern Regiontechnolibrary
 
Developer Friendly API Design
Developer Friendly API DesignDeveloper Friendly API Design
Developer Friendly API Designtheamiableapi
 
Visual Arts on Blackboard
Visual Arts on BlackboardVisual Arts on Blackboard
Visual Arts on BlackboardDaniela Gachago
 
Re-implementing Thrift using MDE
Re-implementing Thrift using MDERe-implementing Thrift using MDE
Re-implementing Thrift using MDESina Madani
 
Migrating to IntelliJ IDEA from Eclipse
Migrating to IntelliJ IDEA from EclipseMigrating to IntelliJ IDEA from Eclipse
Migrating to IntelliJ IDEA from EclipseTrisha Gee
 

Destacado (20)

Code Review Matters and Manners
Code Review Matters and MannersCode Review Matters and Manners
Code Review Matters and Manners
 
[Suriano & Perry] [Library Design: Community Transformation] IFLA LBES 2016
[Suriano & Perry] [Library Design: Community Transformation] IFLA LBES 2016[Suriano & Perry] [Library Design: Community Transformation] IFLA LBES 2016
[Suriano & Perry] [Library Design: Community Transformation] IFLA LBES 2016
 
Public Library Design
Public Library DesignPublic Library Design
Public Library Design
 
Peckham Library Case Study
Peckham Library Case StudyPeckham Library Case Study
Peckham Library Case Study
 
ARCHITECTURAL STANDARDS
ARCHITECTURAL STANDARDSARCHITECTURAL STANDARDS
ARCHITECTURAL STANDARDS
 
Library Design and Architecture - 2012
Library Design and Architecture - 2012Library Design and Architecture - 2012
Library Design and Architecture - 2012
 
Is Groovy better for testing than Java?
Is Groovy better for testing than Java?Is Groovy better for testing than Java?
Is Groovy better for testing than Java?
 
Hanna Springs Sculpture Garden
Hanna Springs Sculpture GardenHanna Springs Sculpture Garden
Hanna Springs Sculpture Garden
 
Forrest Dweller Sculpture Garden
Forrest Dweller Sculpture GardenForrest Dweller Sculpture Garden
Forrest Dweller Sculpture Garden
 
Space Solutions in Makerspaces at Darien Library
Space Solutions in Makerspaces at Darien LibrarySpace Solutions in Makerspaces at Darien Library
Space Solutions in Makerspaces at Darien Library
 
PAARL Standards for Academic Libraries 2010 (Final Draft Proposal)
PAARL Standards for Academic Libraries 2010 (Final Draft Proposal)PAARL Standards for Academic Libraries 2010 (Final Draft Proposal)
PAARL Standards for Academic Libraries 2010 (Final Draft Proposal)
 
Presentation by IPS Yale Center for British Art 2014 Fellow Alice Insley
Presentation by IPS Yale Center for British Art 2014 Fellow Alice InsleyPresentation by IPS Yale Center for British Art 2014 Fellow Alice Insley
Presentation by IPS Yale Center for British Art 2014 Fellow Alice Insley
 
Library Design for the 21st Century Learner: CEFPI Southern Region
Library Design for the 21st Century Learner:  CEFPI Southern RegionLibrary Design for the 21st Century Learner:  CEFPI Southern Region
Library Design for the 21st Century Learner: CEFPI Southern Region
 
Raskar 6Sight Keynote Talk Nov09
Raskar 6Sight Keynote Talk Nov09Raskar 6Sight Keynote Talk Nov09
Raskar 6Sight Keynote Talk Nov09
 
Java library synopsis
Java library synopsisJava library synopsis
Java library synopsis
 
Developer Friendly API Design
Developer Friendly API DesignDeveloper Friendly API Design
Developer Friendly API Design
 
The beginning of visual art and design
The beginning of visual art and designThe beginning of visual art and design
The beginning of visual art and design
 
Visual Arts on Blackboard
Visual Arts on BlackboardVisual Arts on Blackboard
Visual Arts on Blackboard
 
Re-implementing Thrift using MDE
Re-implementing Thrift using MDERe-implementing Thrift using MDE
Re-implementing Thrift using MDE
 
Migrating to IntelliJ IDEA from Eclipse
Migrating to IntelliJ IDEA from EclipseMigrating to IntelliJ IDEA from Eclipse
Migrating to IntelliJ IDEA from Eclipse
 

Similar a Java SE 8 library design

New features in jdk8 iti
New features in jdk8 itiNew features in jdk8 iti
New features in jdk8 itiAhmed mar3y
 
Gude for C++11 in Apache Traffic Server
Gude for C++11 in Apache Traffic ServerGude for C++11 in Apache Traffic Server
Gude for C++11 in Apache Traffic ServerApache Traffic Server
 
Modern Java Features
Modern Java Features Modern Java Features
Modern Java Features Florian Hopf
 
Custom Pregel Algorithms in ArangoDB
Custom Pregel Algorithms in ArangoDBCustom Pregel Algorithms in ArangoDB
Custom Pregel Algorithms in ArangoDBArangoDB Database
 
Building Your First Apache Apex Application
Building Your First Apache Apex ApplicationBuilding Your First Apache Apex Application
Building Your First Apache Apex ApplicationApache Apex
 
Building your first aplication using Apache Apex
Building your first aplication using Apache ApexBuilding your first aplication using Apache Apex
Building your first aplication using Apache ApexYogi Devendra Vyavahare
 
Design and Implementation of the Security Graph Language
Design and Implementation of the Security Graph LanguageDesign and Implementation of the Security Graph Language
Design and Implementation of the Security Graph LanguageAsankhaya Sharma
 
Hadoop and HBase experiences in perf log project
Hadoop and HBase experiences in perf log projectHadoop and HBase experiences in perf log project
Hadoop and HBase experiences in perf log projectMao Geng
 
Scala is java8.next()
Scala is java8.next()Scala is java8.next()
Scala is java8.next()daewon jeong
 
ReactiveX
ReactiveXReactiveX
ReactiveXBADR
 
Unifying Frontend and Backend Development with Scala - ScalaCon 2021
Unifying Frontend and Backend Development with Scala - ScalaCon 2021Unifying Frontend and Backend Development with Scala - ScalaCon 2021
Unifying Frontend and Backend Development with Scala - ScalaCon 2021Taro L. Saito
 
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)
 
Dart the Better JavaScript
Dart the Better JavaScriptDart the Better JavaScript
Dart the Better JavaScriptJorg Janke
 
OpenDaylight and YANG
OpenDaylight and YANGOpenDaylight and YANG
OpenDaylight and YANGCoreStack
 
Introduction to Structured Streaming
Introduction to Structured StreamingIntroduction to Structured Streaming
Introduction to Structured StreamingKnoldus Inc.
 
What's new in java 8
What's new in java 8What's new in java 8
What's new in java 8Dian Aditya
 
Functional Programming in Java
Functional Programming in JavaFunctional Programming in Java
Functional Programming in JavaJim Bethancourt
 

Similar a Java SE 8 library design (20)

Java 8
Java 8Java 8
Java 8
 
New features in jdk8 iti
New features in jdk8 itiNew features in jdk8 iti
New features in jdk8 iti
 
Gude for C++11 in Apache Traffic Server
Gude for C++11 in Apache Traffic ServerGude for C++11 in Apache Traffic Server
Gude for C++11 in Apache Traffic Server
 
Modern Java Features
Modern Java Features Modern Java Features
Modern Java Features
 
Custom Pregel Algorithms in ArangoDB
Custom Pregel Algorithms in ArangoDBCustom Pregel Algorithms in ArangoDB
Custom Pregel Algorithms in ArangoDB
 
Building Your First Apache Apex Application
Building Your First Apache Apex ApplicationBuilding Your First Apache Apex Application
Building Your First Apache Apex Application
 
Building your first aplication using Apache Apex
Building your first aplication using Apache ApexBuilding your first aplication using Apache Apex
Building your first aplication using Apache Apex
 
Design and Implementation of the Security Graph Language
Design and Implementation of the Security Graph LanguageDesign and Implementation of the Security Graph Language
Design and Implementation of the Security Graph Language
 
Hadoop and HBase experiences in perf log project
Hadoop and HBase experiences in perf log projectHadoop and HBase experiences in perf log project
Hadoop and HBase experiences in perf log project
 
Scala is java8.next()
Scala is java8.next()Scala is java8.next()
Scala is java8.next()
 
What`s New in Java 8
What`s New in Java 8What`s New in Java 8
What`s New in Java 8
 
ReactiveX
ReactiveXReactiveX
ReactiveX
 
Unifying Frontend and Backend Development with Scala - ScalaCon 2021
Unifying Frontend and Backend Development with Scala - ScalaCon 2021Unifying Frontend and Backend Development with Scala - ScalaCon 2021
Unifying Frontend and Backend Development with Scala - ScalaCon 2021
 
Lambdas in Java 8
Lambdas in Java 8Lambdas in Java 8
Lambdas in Java 8
 
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
 
Dart the Better JavaScript
Dart the Better JavaScriptDart the Better JavaScript
Dart the Better JavaScript
 
OpenDaylight and YANG
OpenDaylight and YANGOpenDaylight and YANG
OpenDaylight and YANG
 
Introduction to Structured Streaming
Introduction to Structured StreamingIntroduction to Structured Streaming
Introduction to Structured Streaming
 
What's new in java 8
What's new in java 8What's new in java 8
What's new in java 8
 
Functional Programming in Java
Functional Programming in JavaFunctional Programming in Java
Functional Programming in Java
 

Último

Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 

Último (20)

Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 

Java SE 8 library design

  • 1. Java SE 8 Library Design Using the new features well Stephen Colebourne Engineering Lead, OpenGamma October 2016
  • 2. Stephen Colebourne ● Java Champion, regular conference speaker ● Best known for date & time - Joda-Time and JSR-310 ● More Joda projects - http://www.joda.org ● Major contributions in Apache Commons ● Blog - http://blog.joda.org ● Worked at OpenGamma for 6 years
  • 3. Strata, from OpenGamma ● Open Source market risk library ● Valuation and risk calcs for finance ○ interest rate swap, FRA, CDS ● Great example of Java SE 8 coding style http://strata.opengamma.io/
  • 5. Introduction ● Java SE 8 is a major update to Java ● Major new features ○ Lambdas ○ Streams ○ Methods on interfaces ○ Date and Time
  • 6. Introduction ● Essential to rethink how you code ● Reconsider coding conventions ● Appreciate new design options
  • 7. Agenda ● Lambdas ● Streams ● Design with Lambdas ● Abstraction ● Immutability ● Interfaces ● Optional ● Odds and Ends
  • 9. Lambdas ● Block of code ○ like an anonymous inner class ● Always assigned to a Functional Interface ○ an interface with one abstract method ○ Runnable, Callable, Comparator ● Uses target typing ○ context determines type of the lambda
  • 10. // Java 7 List<Person> people = loadPeople(); Collections.sort(people, new Comparator<Person>() { @Override public int compare(Person p1, Person p2) { return p1.name.compareTo(p2.name); } }); Lambdas public interface Comparator<T> { int compare(T obj1, T obj2); } // Java 7 Collections.sort(people, new Comparator<Person>() { @Override public int compare(Person p1, Person p2) { return p1.name.compareTo(p2.name); } });
  • 11. // Java 7 List<Person> people = loadPeople(); Collections.sort(people, new Comparator<Person>() { @Override public int compare(Person p1, Person p2) { return p1.name.compareTo(p2.name); } }); Lambdas public interface Comparator<T> { int compare(T obj1, T obj2); } // Java 7 Collections.sort(people, new Comparator<Person>() { @Override public int compare(Person p1, Person p2) { return p1.name.compareTo(p2.name); } });
  • 12. // Java 7 List<Person> people = loadPeople(); Collections.sort(people, new Comparator<Person>() { @Override public int compare(Person p1, Person p2) { return p1.name.compareTo(p2.name); } }); Lambdas public interface Comparator<T> { int compare(T obj1, T obj2); } // Java 8 people.sort((p1, p2) -> p1.name.compareTo(p2.name));
  • 13. Top tips for Lambdas ● Use lambdas wherever appropriate ● Mostly, they just work ● Sometimes, the compiler needs a hint ○ use local variable ○ add the type to the lambda parameter
  • 14. Lambdas Lambdas affect code but do they affect design?
  • 16. Streams ● Many loops have a similar "shape" ● Repetitive design patterns ● Stream library provides a way to abstract this ● Lambdas used to pass the interesting bits
  • 17. Streams List<Trade> trades = loadTrades(); List<Money> valued = new ArrayList<>(); for (Trade t : trades) { if (t.isActive()) { Money pv = t.presentValue(); valued.add(pv); } }
  • 18. Streams List<Trade> trades = loadTrades(); List<Money> valued = new ArrayList<>(); for (Trade t : trades) { if (t.isActive()) { Money pv = t.presentValue(); valued.add(pv); } }
  • 19. Streams List<Trade> trades = loadTrades(); List<Money> valued = trades.stream() .filter(t -> t.isActive()) .map(t -> t.presentValue()) .collect(Collectors.toList());
  • 20. Streams ● New stream() method on Collection ● Sequence of operations on underlying data ● Logic passed in using a lambda ○ filter() to retain/remove ○ map() to change ○ reduce() to summarise ○ sorted() to sort using a comparator
  • 21. Streams trades.stream() .filter(t -> t.isActive()) .map(t -> t.presentValue()) .collect(Collectors.toList());
  • 22. Streams trades.stream() .filter(new Predicate<Trade>() { public boolean test(Trade t) { return t.isActive(); } }) .map(new Function<Trade, Money>() { public Money apply(Trade t) { return t.presentValue(); } }) .collect(Collectors.toList());
  • 23. Streams Stream API not practical without lambdas
  • 24. Exceptions in Streams ● For-each loop is a language feature ● Streams are implemented using regular methods ● Big difference in stack traces
  • 25. Exceptions in Streams java.lang.IllegalArgumentException: Oops at com.opengamma.strata.calc.DefaultCalculationRunner.lambda$2(DefaultCalculationRunner.java:98) at java.util.stream.ReferencePipeline$11$1.accept(ReferencePipeline.java:372) at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) at java.util.Iterator.forEachRemaining(Iterator.java:116) at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801) at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481) at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471) at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708) at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499) at com.opengamma.strata.calc.DefaultCalculationRunner.calculate(DefaultCalculationRunner.java:100) at com.opengamma.strata.calc.DefaultCalculationRunner.lambda$0(DefaultCalculationRunner.java:86) at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) at java.util.Iterator.forEachRemaining(Iterator.java:116) at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801) at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481) at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471) at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708) at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499) at com.opengamma.strata.calc.DefaultCalculationRunner.calculate(DefaultCalculationRunner.java:87) at com.opengamma.strata.calc.DefaultCalculationRunnerTest.calculate(DefaultCalculationRunnerTest.java:49) Stack trace of inner stream Stack trace of outer stream
  • 26. Exceptions in Streams java.lang.IllegalArgumentException: Oops at com.opengamma.strata.calc.DefaultCalculationRunner.calculate(DefaultCalculationRunner.java:102) at com.opengamma.strata.calc.DefaultCalculationRunner.calculate(DefaultCalculationRunner.java:87) at com.opengamma.strata.calc.DefaultCalculationRunnerTest.calculate(DefaultCalculationRunnerTest.java:49) Stack trace of for-each loop
  • 27. Top tips for streams ● Stream not always more readable than loop ● Stream exceptions can be much worse ● My advice: ○ use streams for small, localized, pieces of logic ○ be cautious using streams for large scale logic ● Strata uses for-each loops at top level ○ solely for shorter stack traces
  • 29. Design with Lambdas ● Lambda is converted to a functional interface ● Normal interface with one abstract method ● Java SE 8 adds many new functional interfaces ○ Function<T, R> ○ Predicate<T> ○ Supplier<T> ○ Consumer<T> ○ see java.util.function package ● Primitive versions only for long, int, double
  • 30. Functional interfaces ● Learn the standard functional interfaces ● Only create new ones if adding additional value ○ lots of parameters ○ mix of primitive and object parameters ○ feature really needs a good name or Javadoc
  • 31. Functional interface example // API functional interface @FunctionalInterface public interface Perturbation { public abstract double perturb(int index, double value); } // API method that can be used by a lambda public Curve perturbed(Perturbation perturbation) { … } // caller code curve = curve.perturbed((i, v) -> v + 1e-4);
  • 32. Functional interface example // API functional interface @FunctionalInterface public interface Perturbation { public abstract double perturb(int index, double value); } // API method that can be used by a lambda public Curve perturbed(Perturbation perturbation) { … } // caller code curve = curve.perturbed((i, v) -> v + 1e-4); Name has meaning Method signature is complex
  • 33. Time-series example ● A time-series stores changes to a value over time ● Date-based one like Map<LocalDate, Double> ● What if you want to change the values?
  • 34. Time-series example // API method that can be used by a lambda public LocalDateDoubleTimeSeries mapValues(DoubleUnaryOperator mapper){ … } // caller code ts = ts.mapValues(v -> v * 2);
  • 35. Time-series example // API method that can be used by a lambda public LocalDateDoubleTimeSeries mapValues(DoubleUnaryOperator mapper){ … } // caller code ts = ts.mapValues(v -> v * 2); Multiplication - no need for multipliedBy(double) on the API
  • 36. Time-series example // API method that can be used by a lambda public LocalDateDoubleTimeSeries mapValues(DoubleUnaryOperator mapper){ … } // caller code ts = ts.mapValues(v -> v * 2); ts = ts.mapValues(v -> v / 4); Multiplication - no need for multipliedBy(double) on the API Division - no need for dividedBy(double) on the API
  • 37. Design with Lambdas Method taking a lambda can be more flexible design
  • 39. Abstraction ● Two or more classes with the same methods ● Abstract using an interface? ● Lambdas provide an alternative ● Consider an example with static methods ○ no way to abstract that with interfaces...
  • 40. Abstraction // standard API producing results public static Money pv(FraTrade trade, Market md) { … } public static Sens pv01(FraTrade trade, Market md) { … } public static Double par(FraTrade trade, Market md) { … }
  • 41. Abstraction // standard API producing results public static Money pv(FraTrade trade, Market md) { … } public static Sens pv01(FraTrade trade, Market md) { … } public static Double par(FraTrade trade, Market md) { … } // functional interface matching all three methods interface Calc<T> { public abstract T invoke(FraTrade trade, Market market); }
  • 42. Abstraction // create abstraction to access method by "measure" key Map<Measure, Calc> CALCS = ImmutableMap.builder() .put(Measures.PRESENT_VALUE, FraCalcs::pv) .put(Measures.PV01, FraCalcs::pv01) .put(Measures.PAR_RATE, FraCalcs:: par) .build(); // can now invoke using measure return CALCS.get(measure).invoke(trade, market);
  • 43. Abstraction ● Class being abstracted was not changed ● Provides way to abstract over code you do not own ● Less need for reflection
  • 44. Design with Lambdas Lambdas can abstract in dynamic/flexible ways
  • 46. Multi-threaded ● JDK provides many tools for concurrency ● Parallel streams makes it even easier ● But parallel code is not simple to get right
  • 47. Thread problems ● What if trade modified by some other piece of code? ● Check-then-act bug List<Trade> trades = loadTrades(); List<Money> valued = trades.stream() .filter(t -> t.isActive()) .map(t -> presentValue(t)) .collect(Collectors.toList()); Check then Act
  • 48. Immutable ● Threading bugs due to shared mutable state ● One solution is to use immutable beans ● No possibility of check-then-act type bug
  • 49. Immutable beans ● Class should be final ○ no subclasses ● Fields must be final ○ needed for Java Memory Model ● Field types should be immutable ○ eg. don't use java.util.Date ● Factory methods and Builders instead of constructors
  • 50. Immutable beans ● IDEs help you write mutable beans ● Need better tooling for immutable beans ○ AutoValue ○ Immutables.org ○ Joda-Beans ● Strata uses Joda-Beans http://www.joda.org/joda-beans
  • 51. Joda-Beans @BeanDefinition public final TradeInfo implements ImmutableBean { /** The trade identifier. */ @PropertyDefinition(validate = "notNull") private final StandardId tradeId; /** The trade date. */ @PropertyDefinition(validate = "notNull") private final LocalDate tradeDate; }
  • 52. Joda-Beans ● Source code generated for ○ getters ○ builder ○ equals/hashCode/toString ○ properties - like C# ● Can add your own code to the class and still regenerate ● Built in XML, JSON and Binary serialization
  • 53. Immutable beans ● Most systems better using immutability everywhere ● Java SE 8 parallelStream() pushes at this ● Threading issues mostly eliminated ● No class hierarchies, use interfaces
  • 54. Use interfaces Trade ProductTrade ResolvableTrade SwapTrade FraTrade Resolved SwapTrade Resolved FraTrade
  • 55. Use interfaces ● Concrete classes with no hierarchies ● Interfaces provide the hierarchy ● Methods on interfaces make this practical ● All implementations of interface should be immutable ○ "Implementations must be immutable and thread-safe beans." ● Strata uses immutable beans everywhere
  • 56. Immutability It is time to move on from mutable data objects
  • 58. Interfaces ● Two changes to interfaces ● Default methods ○ normal method, but on an interface ○ cannot default equals/hashCode/toString ● Static methods ○ normal static method, but on an interface
  • 59. Coding Style ● Use modifiers in interfaces ● Much clearer now there are different types of method ● Prepares for private methods in Java SE 9 public interface Foo { public static of(String id) { … } public abstract isEmpty(); public default isNotEmpty() { … } }
  • 60. Interfaces ● Methods on interfaces changes design ● Interfaces are part of macro-design ○ lambdas and streams affect micro-design ● Strata uses default and static methods liberally
  • 61. Holiday Calendar ● Strata interface to specify which days are holidays public interface HolidayCalendar { // a normal abstract interface method public abstract isHoliday(LocalDate date); … }
  • 62. Holiday Calendar ● Default methods make the interface more useful public interface HolidayCalendar { public abstract isHoliday(LocalDate date); // check if date is a business day public default isBusinessDay(LocalDate date) { return !isHoliday(date); } }
  • 63. Holiday Calendar ● Default methods make the interface more useful public interface HolidayCalendar { public abstract isHoliday(LocalDate date); // find the next business day public default next(LocalDate date) { LocalDate nextDay = date.plusDays(1); return isHoliday(nextDay) ? next(nextDay) : nextDay; } }
  • 64. Holiday Calendar ● Static methods avoid HolidayCalendarFactory public interface HolidayCalendar { // find holiday calendar by identifier such as DKCO public static of(String id) { // lookup calendar } }
  • 65. Holiday Calendar ● Interface used just as would be expected // find holiday calendar by identifier such as DKCO HolidayCalendar cal = HolidayCalendar.of("DKCO"); // use calendar to select the trade start date LocalDate startDate = cal.next(tradeDate);
  • 66. Interfaces ● Interface now acts as abstract class ○ Only need abstract class if need abstracted state ○ but abstracted state is generally a bad idea ● Interface can now acts as a factory ○ Not suitable for all factory use cases* * In Strata, holiday calendars are not really fixed at startup, but it made a good example for this talk!
  • 67. Package-scoped implementation ● Can the interface be the only public API? ● Can the implementation class be package-scoped? ● Strata uses this pattern a lot
  • 70. Optional and null ● New class Optional added to Java 8 ● Opinions are polarized ○ some think it is the saviour of the universe ○ others think it is useless ● Used pragmatically, can be very useful
  • 71. Optional and null ● Simple concept - two states ○ present, with a value - Optional.of(foo) ○ empty - Optional.empty()
  • 72. Optional and null ● Standard code using null // library, returns null if not found public Foo getValue(String key) { … } // application code must remember to check for null Foo foo = getValue(key); if (foo == null) { foo = Foo.DEFAULT; // or throw an exception }
  • 73. Optional and null ● Standard code using Optional // library, returns Optional if not found public Optional<Foo> findValue(String key) { … } // application code Foo foo = findValue(key).orElse(Foo.DEFAULT); // or Foo foo = findValue(key).orElseThrow( … );
  • 74. Optional and null ● Important that a variable of type Optional is never null ● Prefer methods like map() and orElse() ● Minimise use of isPresent()
  • 75. Optional ● Strata often uses set of 3-methods public abstract Optional<T> findValue(DataId<T> id); public default boolean containsValue(DataId<T> id) { return findValue(id).isPresent(); } public default T getValue(DataId<T> id) { return findValue(id).orElseThrow( () -> new MarketDataException()); }
  • 76. Optional ● Optional is a class ● Some memory/performance cost to using it ● Not serializable ● Not ideal to be an instance variable ● JDK authors added it for return types ● Use in parameters often annoying for callers ● Use as return type gets best value from concept http://blog.joda.org/2015/08/java-se-8-optional-pragmatic-approach.html
  • 77. Optional in Strata ● Strata has no exposed nulls ● No part of the API will return null ● Optional used when something is optional ● Pragmatically, null is used within classes
  • 78. Optional Use Optional in a pragmatic way
  • 80. Java SE 8 version ● Use Java SE 8 update 40 or later ○ preferably use the latest available ● Earlier versions have annoying lambda/javac issues
  • 81. Internal JDK packages ● Java SE 9 will remove access to some JDK packages ○ sun.* ○ com.sun.* ○ com.oracle.* ● Now is the time to prepare for this ○ Avoid sun.misc.Unsafe ○ Stick to the standard JDK API
  • 82. Parameters ● Java SE 8 can reflect on parameter names ● Avoids need for additional libraries like paranamer ● Not enabled by default, must choose to include data
  • 83. Checked exceptions ● Checked exceptions can be made to disappear ● Helper methods can convert to runtime exceptions Unchecked.wrap(() -> { // any code that might throw a checked exception // converted to a runtime exception });
  • 85. Summary ● Lots of good stuff in Java SE 8 ● Design and coding standards change ● Lots more potential to abstract, but don't over-use ● Methods on interfaces add a lot of power
  • 86. Key Strata design features ● Immutable data objects, using Joda-Beans ● Static methods on interfaces, package-scope impls ● Make use of new abstractions ● Beware stack traces with streams ● Pragmatic use of Optional, null never returned from API
  • 87. Work in Finance? ● Take a look at OpenGamma Strata ○ developed from the ground up in Java 8 ○ lots of good Java 8 techniques and utilities ● High quality library for market risk ○ day counts, schedules, holidays, indices ○ models and pricing for swaps, FRAs, swaptions, FX, futures… ○ open source and stable release v1.1 http://strata.opengamma.io/