jsr 354 - money and currency api for java

34
JSR 354 Java Money and Currency API Werner Keil Build Manager, DevOps Expert, Agile Coach Maersk Line EG Member, JSR 354 @wernerkeil

Upload: werner-keil

Post on 28-Nov-2014

3.468 views

Category:

Economy & Finance


2 download

DESCRIPTION

Presentation of the Java Standard API for handling Currencies, monetary values, arithmetic, and foreign exchange

TRANSCRIPT

Page 1: JSR 354 - Money and Currency API for Java

JSR 354 Java Money and Currency API

Werner KeilBuild Manager, DevOps Expert,

Agile CoachMaersk Line

EG Member, JSR 354@wernerkeil

Page 2: JSR 354 - Money and Currency API for Java

•Consultant – Coach

•Creative Cosmopolitan

•Open Source Evangelist

•Software Architect

• Java Godfather

• JCP Executive Committee Member

•Eclipse UOMo Project Lead

•DevOps Guy

Werner Keil - BioWerner Keil - Bio

2

Page 3: JSR 354 - Money and Currency API for Java

Show me the Money!Show me the Money!

Page 4: JSR 354 - Money and Currency API for Java

4

AgendaAgenda

•History

•Motivation

•The JSR

•Virtual Currencies

•Currency Exchange

•Demos

•Q&A

Page 5: JSR 354 - Money and Currency API for Java

5

HistoryHistory

Page 6: JSR 354 - Money and Currency API for Java

6

Earlier ApproachesEarlier Approaches

Martin Fowler: A large proportion of the computers in this world manipulate money, so it's always puzzled me that money isn't actually a first class data type in any mainstream programming language. The lack of a type causes problems, the most obvious surrounding currencies…

see http://martinfowler.com/eaaCatalog/money.html

Page 7: JSR 354 - Money and Currency API for Java

7

Earlier Approaches (2)Earlier Approaches (2)

Eric Evans – Time and Money: On project after project, software developers have to reinvent the wheel, creating objects for simple recurring concepts such as "money" and "currency". Although most languages have a "date" or "time" object, these are rudimentary, and do not cover many needs, such as recurring sequences of time, durations of time, or intervals of time. …see http://timeandmoney.sourceforge.net/

To be quite frank, their code isn‘t more than an academic POC, factories called dollars() or euros() are useless in real globally deployed frameworks, but he made a good point.

Page 8: JSR 354 - Money and Currency API for Java

8

MoneyDanceMoneyDance

Page 9: JSR 354 - Money and Currency API for Java

Motivation

Page 10: JSR 354 - Money and Currency API for Java

10

SummarySummary

•This JSR will providea money andcurrency API forJava, targeted at all users of currencies andmonetary amounts in Java.

•TheAPI will providesupportfor standard ISO-4217 and Custom (e.g. Virtual) currencies, as well asrepresentation of a monetary amount.

• It will supportcurrency arithmetic, even across different currencies, and foreign currency exchange.

•Additionally, implementation details surroundingserialization andthread safety are to be considered

Page 11: JSR 354 - Money and Currency API for Java

11

Why is it needed?Why is it needed?

•Monetary values are a key feature to many applications.

•Theexisting java.util.Currency class is strictly a structure used for representing ISO-4217 standard currencies.

•No standard value type to represent a monetaryamount.

•No support for currency arithmetic or conversion

Page 12: JSR 354 - Money and Currency API for Java

12

ChallengesChallenges

•Keep it simple – Remember the most common use case

•Adding currency values e.g. in an e-commerce app.

•Performance

•How to support low latency applications, such as High Frequency Trading apps.

•Precision

•There can potentially be differing precisions specified for arithmetic, currency exchange and formatting

Page 13: JSR 354 - Money and Currency API for Java

13

Challenges (2)Challenges (2)

•Formatting

•Requirement should be to use existing Number Formats.

•However there is no existing format representing for example Indian Rupees:which might look something like this: 12,34,00,000

•Natural language support for non-decimal valuations for example

•Lakhs

•Crores

•1 Lakh = 100,000

•1 Crore = 100 Lakh

Page 14: JSR 354 - Money and Currency API for Java

14

Challenges (3)Challenges (3)

•Formatting

•12,34,56,000.21 is written12 Crore, 34 Lakh, 56 Thousand Rupees and 21 Paise

•Support for non-standard rounding modes

Page 15: JSR 354 - Money and Currency API for Java

15

Non-standard Rounding ModesNon-standard Rounding Modes

• It is a big world, and each country has its regulations and cultural nuances for expressing currencies in natural language, rounding policies, groupings, etc.

•For example, in Argentina rounding is prescribed for the third digit after the decimal point:If the third digit is 2 or less, change it to 0 or drop it.If the third digit is between 3 and 7, change it to 5.If the third digit is 8 or more, add one to the second digit and drop the third digit or change it to 0.

Page 16: JSR 354 - Money and Currency API for Java

16

Non-standard Rounding – ArgentinaNon-standard Rounding – Argentina

Argentina Rounding Examples

Switzerland uses a similar rounding strategy.

Original Number

Rounded Notes

123.452 123.45 Third digit<3 round down

123.456 123.455 3<=third digit<=7 change to 5

123.459 123.46 Third digit>=8 round up

Page 17: JSR 354 - Money and Currency API for Java

17

RisksRisks

Plan – “Money and Currency” is a formidable and dynamic category with regional dependencies, requiring programmers, business users, international accountants, and attorneys.

Risk – Incomplete or outdated spec

Mitigation – Resulting API should be flexible, let application developer

change implementation as needed.

Page 18: JSR 354 - Money and Currency API for Java

18

Risks (2)Risks (2)

Plan – There is also a Java dependency on JDK NumberFormat.

Risk – NumberFormat may require coordinated modifications.

Mitigation – Coordinate with JDK release;

Supply NumberFormats and similar classes that augment JDK content.

Plan – There is also a Java dependency on JDK NumberFormat.

Risk – NumberFormat may require coordinated modifications.

Mitigation – Coordinate with JDK release;

Supply NumberFormats and similar classes that augment JDK content.

Page 19: JSR 354 - Money and Currency API for Java

The JSR

Page 20: JSR 354 - Money and Currency API for Java

20

Expert Group MembersExpert Group Members

•Credit Suisse

•Goldman Sachs

•Stephen Colebourne

•Ben Evans

•Werner Keil

•Bob Lee

Page 21: JSR 354 - Money and Currency API for Java

21

Supporting the JSRSupporting the JSR

•Credit Suisse

•Caxton Associates

•Goldman Sachs

• JP Morgan/Chase

•London Java Community

•Stephen Colebourne

•Werner Keil

Page 22: JSR 354 - Money and Currency API for Java

22

ScheduleSchedule

•Targeted to Java 9

•Aiming at Java ME/Embedded 8 or 9• Following the EC Merge and Standard/Embedded harmonization, no JSR

should be SE/EE or ME only, with very few, specialized exceptions. Money is so important, and has almost no legacy in the JDK except java.util.Currency, that it should be supported by ALL POSSIBLE platforms, except maybe JavaCard for now.

•With back-port to previous versions still supported and in relevant use

Page 23: JSR 354 - Money and Currency API for Java

23

Virtual CurrenciesVirtual Currencies

Page 24: JSR 354 - Money and Currency API for Java

24

Facebook CreditsFacebook Credits

What are Facebook Credits?

•Facebook Credits are a virtual currency you can use to buy virtual goods in any games or apps of the Facebook platform that accept payments. You can purchase Facebook Credits directly from within an app using your credit card, PayPal, mobile phone and many other local payment methods.

► Hence any such purchase is practically a conversion, similar to if you buy a foreign currency when

travelling abroad☺

Page 25: JSR 354 - Money and Currency API for Java

25

Top 10 Video Game CurrenciesTop 10 Video Game Currencies

1.Gold

2.Gil

3.Rupees (not Indian;-)

4.Credits

5.Gold Rings

6.Hearts

7.Zenny

8.Potch

9.Munny

10.Nuyen

Page 26: JSR 354 - Money and Currency API for Java

26

World CurrenciesWorld Currencies

Page 27: JSR 354 - Money and Currency API for Java

Currency ExchangeCurrency Exchange

Page 28: JSR 354 - Money and Currency API for Java

Currency Conversion (JScience)Currency Conversion (JScience)

28

Page 29: JSR 354 - Money and Currency API for Java

Online Currency Conversion ExampleOnline Currency Conversion Example

29

Page 30: JSR 354 - Money and Currency API for Java

Trading Application ExampleTrading Application ExampleWhat happens, if we use built in java.util.Currency and Standard

JSP formats

30

Page 31: JSR 354 - Money and Currency API for Java

Demos

Page 32: JSR 354 - Money and Currency API for Java

Q & A

Page 33: JSR 354 - Money and Currency API for Java

• The JSR: http://jcp.org/en/jsr/summary?id=354

• java.net Project: http://java.net/projects/javamoney/

• GitHub Project: http://github.com/JavaMoney/

LinksLinks

Page 34: JSR 354 - Money and Currency API for Java

• Eclipse UOMo: http://www.eclipse.org/uomo/

• JScience:http://www.jscience.org

• JodaMoney: http://joda-money.sourceforge.net/

Links (2)Links (2)