SlideShare una empresa de Scribd logo
1 de 28
Descargar para leer sin conexión
Introduction to JSR 354 – Java Money & Currency
Anatole Tresch, Werner Keil
atsticks@java.net @atsticks keilw@java.net @wernerkeil
http://java.net/projects/javamoney
Bios
Anatole Tresch
• Consultant - Coach
• Software and Framework
Architect
• Open Source Addicted
• Credit Suisse
• Specification Lead
JSR 354
Anatole Tresch, Werner Keil Introduction to JSR 354
http://java.net/projects/javamoney
Werner Keil
• Consultant – Coach
• Creative Cosmopolitan
• Open Source Evangelist
• Software Architect
• Java Godfather
• JCP Executive Committee
Member
• Eclipse UOMo Project Lead
• DevOps Guy
• Expert Group JSR 354
Agenda
• History and Motivation
• Overview
• Amounts, Currencies
• Numeric precision, Rounding
• Formatting & Parsing
• Currency Conversion
• Provider & Extensions
• Demo
Anatole Tresch, Werner Keil Introduction to JSR 354
http://java.net/projects/javamoney
Scope: Platform (SE)
Scope: Standalone
History and Motivation
Earlier Approaches
Anatole Tresch, Werner Keil Introduction to JSR 354
http://java.net/projects/javamoney
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. …
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.
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/eaaCa
talog/money.html
Motivation
Anatole Tresch, Werner Keil
 Monetary values are a key feature to many
applications
 The existing java.util.Currency class is
strictly a structure used for representing ISO-4217
standard currencies.
 No standard value type to represent a monetary
amount.
 No support for currency arithmetic or conversion.
 JDK Formatting features lack of flexibility.
Introduction to JSR 354
http://java.net/projects/javamoney
Schedule
Anatole Tresch, Werner Keil
• Targeting 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
• EDR: Beginning of April 2013
Introduction to JSR 354
http://java.net/projects/javamoney
Overview
Overview on JSR 354
Anatole Tresch, Werner Keil
• Core API: javax.money
• CurrencyUnit, MonetaryAmount and exceptions
• Conversion API: javax.money.conversion
• ExchangeRate, CurrencyConverter
• Formatting: javax.money.format
• LocalizationStyle, ItemFormatter, ItemParser
• Provider singleton: javax.money .Monetary
• Extensions: javax.money.ext
• Region support, Calculations
• Reference Implementation: net.java.javamoney.ri
• TCK
Introduction to JSR 354
http://java.net/projects/javamoney
Amounts & Currencies
javax.money
Currencies: What’s all in ISO 4217
Anatole Tresch, Werner Keil
• Special Codes
• For precious metals (XAU, XAG)
• for testing (XTS)
• no currency (XXX)
• Supranational currencies, e.g. East Caribbean dollar, the CFP franc, the CFA franc.
• «Ambiguities»:
• CFA franc: West African CFA franc and the Central African CFA franc.
Although theoretically separate, the two CFA franc currencies are effectively
interchangeable.
• Switzerland: CHF, CHE (WIR-EURO), CHW (WIR)
• USA: USD, USN (next day), USS (same day)
• Unmodeled Aspects:
• Different legal acceptance, e.g. Indian Rupees are accepted in Buthan/Nepal,
but not vice versa
• Minor units 1/100, 1/1000, but also 1/5 (Mauritania,
Madagaskar), 0.00000001 (BitCoin)
Introduction to JSR 354
http://java.net/projects/javamoney
Virtual Currencies
Anatole Tresch, Werner Keil
• Video Game Currencies (Gold,Gil, Rupees, Credits, Gold Rings,
Hearts, Zenny, Potch, Munny, Nuyen…)
• 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.
• Bitcoin (sign: BTC) is a decentralized digital currency
based on an open-source, peer-to-peer internet protocol.
It was introduced by a pseudonymous developer named
Satoshi Nakamoto in 2009.
Introduction to JSR 354
http://java.net/projects/javamoney
Limitations of java.util.Currency
Anatole Tresch, Werner Keil
• No support for historical Currencies
• No support for non standard Currencies (e.g. cows or
camels)
• No support for virtual
Currencies (Lindon Dollars,
BitCoin, Social Currencies)
• No support for custom
schemes (e.g. legacy codes)
• Only access by currency
code, or Locale
• No support for special use
cases/extensions
Introduction to JSR 354
http://java.net/projects/javamoney
public interface CurrencyUnit{
public String getCurrencyCode();
public int getNumericCode();
public int
getDefaultFractionDigits();
// new methods
public String getNamespace();
public boolean isLegalTender();
public boolean isVirtual();
public Long getValidFrom();
public Long getValidUntil();
public <T> T getAttribute(
String key, Class<T> type);
public Enumeration<String>
getAttributeKeys();
public Class<?> getAttributeType(
String key);
}
Monetary Amount
Anatole Tresch, Werner Keil
• Amount = Number + Currency + Operations
• How to represent the numeric amount?
• Performant (e.g. for trading)
• Precise (e.g. for calculations)
• For small numbers (e.g. webshop)
• For huge Numbers (e.g. risk calulations, statistics)
• Rounding, Precision, Scale
Introduction to JSR 354
http://java.net/projects/javamoney
Solution: allow different number representations!
Monetary Amount (Continued)
Anatole Tresch, Werner Keil Introduction to JSR 354
http://java.net/projects/javamoney
public interface MonetaryAmount{
public CurrencyUnit getCurrency();
public Class<?> getNumberType();
public <T> T asType(Class<T>);
public int intValue(); public int intValueExact();
public long longValue(); public long longValueExact();
[…]
public MonetaryAmount abs();
public MonetaryAmount min(…);
public MonetaryAmount max(…);
public MonetaryAmount add(…);
public MonetaryAmount subtract(…);
public MonetaryAmount divide(…);
public MonetaryAmount[] divideAndRemainder(…);
public MonetaryAmount divideToIntegralValue(…);
public MonetaryAmount remainder(…);
public MonetaryAmount multiply(…);
public MonetaryAmount with(Number amount);
[…]
public int getScale(); public int getPrecision();
[…]
public boolean isPositive(); public boolean isPositiveOrZero();
public boolean isNegative(); public boolean isNegativeOrZero();
public boolean lessThan(…);
public boolean lessThanOrEqualTo(…);
[…]
}
Access Currency and
Number part.
Algorithmic
Operations…
Data Representation
and Comparison .
Precision & Rounding
javax.money
Types of Numeric Precision
Anatole Tresch, Werner Keil
• Internal Precision (implied by number representation and arithmetic)
• External Precision (rounding applied when a numeric value of an
amount is accessed)
• Formatting Precision (rounding applied for display and output)
• Interoperability Challenges
• Different precision/scale
• Different numeric representations
• Serialization
By default only internal rounding is applied automatically.
Introduction to JSR 354
http://java.net/projects/javamoney
Rounding rounding =
Monetary.getRoundingProvider().
getRounding(“Argentina”);
MontaryAmount myAmount = …;
MonetaryAmount rounded =
rounding.round(myAmount);
Rounding API
Anatole Tresch, Werner Keil
• External Rounding and Formatting Rounding can be implemented in many ways,
depending on the use cases:
• Example for non standard-rounding: Argentina:
• 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.
Introduction to JSR 354
http://java.net/projects/javamoney
public interface Rounding{
public MonetaryAmount round(MonetaryAmount );
}
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
Formatting & Parsing
javax.money.format
Formatting & Parsing Challenges
Anatole Tresch, Werner Keil
• Different Locale for Translation, Dates, Time, Numbers,
Currencies
• Additional configuration
• Currency Placement, Rounding, Lenient Fractions, Min, Max,
legal units, customer group etc.
• Natural language support
for non-decimal valuations,eg.
– Lakhs, Crores (1 Lakh =
100,000, 1 Crore = 100 Lakh)
– INR 12,34,56,000.21 is written
12 Crore, 34 Lakh, 56 Thousand
Rupees and 21 Paise
• Different styles.
Introduction to JSR 354
http://java.net/projects/javamoney
Define LocalizationStyle and
according ItemFormatter/-Parser
public class LocalizationStyle
implements Serializable {
[…]
public String getId();
public Locale getTranslationLocale();
public Locale getNumberLocale();
public Locale getDateLocale();
public Locale getTimeLocale();
public Map<String, Object> getAttributes() ;
public <T> T getAttribute(
String key, Class<T> type);
public static LocalizationStyle of(
Locale locale);
public boolean isDefaultStyle() ;
[…]
}
Currency Conversion
javax.money.conversion
Currency Conversion
Anatole Tresch, Werner Keil
• ExchangeRateType
• ExchangeRate:
• ExchangeRateType
• Source, target currency
• Conversion Factor
• Validity Range (from/until)
• Provider (optional)
• Direct/Derived Rate
• Attributes
• ExchangeRateProvider
• CurrencyConverter
Introduction to JSR 354
http://java.net/projects/javamoney
public interface ExchangeRate {
public ExchangeRateType getExchangeRateType();
public CurrencyUnit getSource();
public CurrencyUnit getTarget();
public Number getFactor();
public Long getValidFrom();
public Long getValidUntil();
public boolean isValid();
public String getProvider();
public ExchangeRate[] getExchangeRateChain();
public boolean isDerived();
public boolean isIdentity();
public <T> T getAttribute(String key,
Class<T> type);
public Enumeration<String> getAttributeKeys();
public Class<?> getAttributeType(String key);
}
ExchangeRateType rateType = …;
CurrencyConverter conv =
Monetary.getCurrencyConverter(rateType);
Provider & Extensions
javax.money, javax.money.ext
Provider: Monetary Singleton
Anatole Tresch, Werner Keil
• javax.money.Monetary provides access to all
components
• Loading mechanism is configurable, e.g.
• ServiceLoader (default)
• CDI
• Spring
• …
Introduction to JSR 354
http://java.net/projects/javamoney
public final class Monetary{
public static MonetaryAmountProvider getMonetaryAmountProvider(
Class<?> numberClass);
public static MonetaryAmountProvider getMonetaryAmountProvider()
public static CurrencyUnitProvider getCurrencyUnitProvider();
public static ConversionProvider getConversionProvider();
public static ItemFormatterFactory getItemFormatterFactory();
public static ItemParserFactory getItemParserFactory();
public static RoundingProvider getRoundingProvider();
public static <T> T getExtension(Class<T> extensionType);
public static boolean isExtensionAvailable(Class<?> type);
public static Enumeration<Class<?>> getLoadedExtensions();
}+Extensions
Extensions
Anatole Tresch, Werner Keil
• Idea: allow registration of additional functionalities into Monetary:
• Compound Values
• Utilities and Calculation Modules
• Regions/Regional Providers
• To be discussed:
• what extensions should be part of the JSR?
• Should extensions by part of this JSR at all?
Introduction to JSR 354
http://java.net/projects/javamoney
CalculationUtils utils =
Monetary.getExtension(CalculationUtils.class);
utils.total(…);
Demo
Anatole Tresch, Werner Keil Introduction to JSR 354
http://java.net/projects/javamoney
Q & A
Anatole Tresch, Werner Keil Introduction to JSR 354
http://java.net/projects/javamoney
Stay Tuned
Anatole Tresch, Werner Keil
• JSR 354: http://jcp.org
• Java.net Project: http://java.net/projects/javamoney
• GitHub Project: https://github.com/JavaMoney/javamoney
• Eclipse UOMo: http://www.eclipse.org/uomo
• Twitter: @jsr354
Introduction to JSR 354
http://java.net/projects/javamoney

Más contenido relacionado

Similar a Introduction to JSR 354 - Standard Java API for Currency and Money

Groovy On The Trading Desk
Groovy On The Trading DeskGroovy On The Trading Desk
Groovy On The Trading DeskJonathan Felch
 
Go for the Money - JSR 354
Go for the Money - JSR 354Go for the Money - JSR 354
Go for the Money - JSR 354Anatole Tresch
 
JavaFX - Next Generation Java UI
JavaFX - Next Generation Java UIJavaFX - Next Generation Java UI
JavaFX - Next Generation Java UIYoav Aharoni
 
JSR 354 Hackday - What you can do...
JSR 354 Hackday - What you can do...JSR 354 Hackday - What you can do...
JSR 354 Hackday - What you can do...Anatole Tresch
 
Cooking your Ravioli "al dente" with Hexagonal Architecture
Cooking your Ravioli "al dente" with Hexagonal ArchitectureCooking your Ravioli "al dente" with Hexagonal Architecture
Cooking your Ravioli "al dente" with Hexagonal ArchitectureJeroen Rosenberg
 
Ethereum Classic Shanghai: Products and Services
Ethereum Classic Shanghai: Products and ServicesEthereum Classic Shanghai: Products and Services
Ethereum Classic Shanghai: Products and ServicesAvtar Sehra
 
Building financial systems in scala
Building financial systems in scalaBuilding financial systems in scala
Building financial systems in scalaoxbow_lakes
 
Build tic tac toe with javascript (4:11 dc)
Build tic tac toe with javascript (4:11 dc)Build tic tac toe with javascript (4:11 dc)
Build tic tac toe with javascript (4:11 dc)Daniel Friedman
 
Rehan_Ali_Updated_Resume_January
Rehan_Ali_Updated_Resume_JanuaryRehan_Ali_Updated_Resume_January
Rehan_Ali_Updated_Resume_JanuaryREHAN ALI
 
Note for Java Programming////////////////
Note for Java Programming////////////////Note for Java Programming////////////////
Note for Java Programming////////////////MeghaKulkarni27
 
Deep dive time series anomaly detection with different Azure Data Services
Deep dive time series anomaly detection with different Azure Data ServicesDeep dive time series anomaly detection with different Azure Data Services
Deep dive time series anomaly detection with different Azure Data ServicesMarco Parenzan
 
Scalable Event Processing with WSO2CEP @ WSO2Con2015eu
Scalable Event Processing with WSO2CEP @  WSO2Con2015euScalable Event Processing with WSO2CEP @  WSO2Con2015eu
Scalable Event Processing with WSO2CEP @ WSO2Con2015euSriskandarajah Suhothayan
 
Oops concepts variables and How to handle variable in testing
Oops concepts variables and How to handle variable in testingOops concepts variables and How to handle variable in testing
Oops concepts variables and How to handle variable in testingNILESH SAWARDEKAR
 
Ethereum: Three Paths to Profits (or Pain)
Ethereum: Three Paths to Profits (or Pain)Ethereum: Three Paths to Profits (or Pain)
Ethereum: Three Paths to Profits (or Pain)Kent Barton
 
Strata, Open Source Market Risk
Strata, Open Source Market RiskStrata, Open Source Market Risk
Strata, Open Source Market RiskStephen Colebourne
 
Sugumar_raja_3exp_Plsql_profile
Sugumar_raja_3exp_Plsql_profileSugumar_raja_3exp_Plsql_profile
Sugumar_raja_3exp_Plsql_profileSugumar Raja
 
Deep Dive Time Series Anomaly Detection in Azure with dotnet
Deep Dive Time Series Anomaly Detection in Azure with dotnetDeep Dive Time Series Anomaly Detection in Azure with dotnet
Deep Dive Time Series Anomaly Detection in Azure with dotnetMarco Parenzan
 

Similar a Introduction to JSR 354 - Standard Java API for Currency and Money (20)

Groovy On The Trading Desk
Groovy On The Trading DeskGroovy On The Trading Desk
Groovy On The Trading Desk
 
Go for the Money - JSR 354
Go for the Money - JSR 354Go for the Money - JSR 354
Go for the Money - JSR 354
 
JavaFX - Next Generation Java UI
JavaFX - Next Generation Java UIJavaFX - Next Generation Java UI
JavaFX - Next Generation Java UI
 
JSR 354 Hackday - What you can do...
JSR 354 Hackday - What you can do...JSR 354 Hackday - What you can do...
JSR 354 Hackday - What you can do...
 
Cooking your Ravioli "al dente" with Hexagonal Architecture
Cooking your Ravioli "al dente" with Hexagonal ArchitectureCooking your Ravioli "al dente" with Hexagonal Architecture
Cooking your Ravioli "al dente" with Hexagonal Architecture
 
JSR 354 LJC-Hackday
JSR 354 LJC-HackdayJSR 354 LJC-Hackday
JSR 354 LJC-Hackday
 
Ethereum Classic Shanghai: Products and Services
Ethereum Classic Shanghai: Products and ServicesEthereum Classic Shanghai: Products and Services
Ethereum Classic Shanghai: Products and Services
 
Building financial systems in scala
Building financial systems in scalaBuilding financial systems in scala
Building financial systems in scala
 
Build tic tac toe with javascript (4:11 dc)
Build tic tac toe with javascript (4:11 dc)Build tic tac toe with javascript (4:11 dc)
Build tic tac toe with javascript (4:11 dc)
 
Rehan_Ali_Updated_Resume_January
Rehan_Ali_Updated_Resume_JanuaryRehan_Ali_Updated_Resume_January
Rehan_Ali_Updated_Resume_January
 
L04 loading metadata
L04 loading metadataL04 loading metadata
L04 loading metadata
 
Note for Java Programming////////////////
Note for Java Programming////////////////Note for Java Programming////////////////
Note for Java Programming////////////////
 
CV Functional
CV FunctionalCV Functional
CV Functional
 
Deep dive time series anomaly detection with different Azure Data Services
Deep dive time series anomaly detection with different Azure Data ServicesDeep dive time series anomaly detection with different Azure Data Services
Deep dive time series anomaly detection with different Azure Data Services
 
Scalable Event Processing with WSO2CEP @ WSO2Con2015eu
Scalable Event Processing with WSO2CEP @  WSO2Con2015euScalable Event Processing with WSO2CEP @  WSO2Con2015eu
Scalable Event Processing with WSO2CEP @ WSO2Con2015eu
 
Oops concepts variables and How to handle variable in testing
Oops concepts variables and How to handle variable in testingOops concepts variables and How to handle variable in testing
Oops concepts variables and How to handle variable in testing
 
Ethereum: Three Paths to Profits (or Pain)
Ethereum: Three Paths to Profits (or Pain)Ethereum: Three Paths to Profits (or Pain)
Ethereum: Three Paths to Profits (or Pain)
 
Strata, Open Source Market Risk
Strata, Open Source Market RiskStrata, Open Source Market Risk
Strata, Open Source Market Risk
 
Sugumar_raja_3exp_Plsql_profile
Sugumar_raja_3exp_Plsql_profileSugumar_raja_3exp_Plsql_profile
Sugumar_raja_3exp_Plsql_profile
 
Deep Dive Time Series Anomaly Detection in Azure with dotnet
Deep Dive Time Series Anomaly Detection in Azure with dotnetDeep Dive Time Series Anomaly Detection in Azure with dotnet
Deep Dive Time Series Anomaly Detection in Azure with dotnet
 

Más de Codemotion

Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...
Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...
Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...Codemotion
 
Pompili - From hero to_zero: The FatalNoise neverending story
Pompili - From hero to_zero: The FatalNoise neverending storyPompili - From hero to_zero: The FatalNoise neverending story
Pompili - From hero to_zero: The FatalNoise neverending storyCodemotion
 
Pastore - Commodore 65 - La storia
Pastore - Commodore 65 - La storiaPastore - Commodore 65 - La storia
Pastore - Commodore 65 - La storiaCodemotion
 
Pennisi - Essere Richard Altwasser
Pennisi - Essere Richard AltwasserPennisi - Essere Richard Altwasser
Pennisi - Essere Richard AltwasserCodemotion
 
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...Codemotion
 
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019Codemotion
 
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019Codemotion
 
Francesco Baldassarri - Deliver Data at Scale - Codemotion Amsterdam 2019 -
Francesco Baldassarri  - Deliver Data at Scale - Codemotion Amsterdam 2019 - Francesco Baldassarri  - Deliver Data at Scale - Codemotion Amsterdam 2019 -
Francesco Baldassarri - Deliver Data at Scale - Codemotion Amsterdam 2019 - Codemotion
 
Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...
Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...
Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...Codemotion
 
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...Codemotion
 
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...Codemotion
 
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...Codemotion
 
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019Codemotion
 
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019Codemotion
 
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019Codemotion
 
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...Codemotion
 
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...Codemotion
 
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019Codemotion
 
Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019
Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019
Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019Codemotion
 
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019Codemotion
 

Más de Codemotion (20)

Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...
Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...
Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...
 
Pompili - From hero to_zero: The FatalNoise neverending story
Pompili - From hero to_zero: The FatalNoise neverending storyPompili - From hero to_zero: The FatalNoise neverending story
Pompili - From hero to_zero: The FatalNoise neverending story
 
Pastore - Commodore 65 - La storia
Pastore - Commodore 65 - La storiaPastore - Commodore 65 - La storia
Pastore - Commodore 65 - La storia
 
Pennisi - Essere Richard Altwasser
Pennisi - Essere Richard AltwasserPennisi - Essere Richard Altwasser
Pennisi - Essere Richard Altwasser
 
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...
 
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
 
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019
 
Francesco Baldassarri - Deliver Data at Scale - Codemotion Amsterdam 2019 -
Francesco Baldassarri  - Deliver Data at Scale - Codemotion Amsterdam 2019 - Francesco Baldassarri  - Deliver Data at Scale - Codemotion Amsterdam 2019 -
Francesco Baldassarri - Deliver Data at Scale - Codemotion Amsterdam 2019 -
 
Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...
Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...
Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...
 
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...
 
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...
 
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...
 
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019
 
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019
 
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
 
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...
 
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...
 
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019
 
Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019
Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019
Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019
 
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019
 

Último

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 

Último (20)

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 

Introduction to JSR 354 - Standard Java API for Currency and Money

  • 1. Introduction to JSR 354 – Java Money & Currency Anatole Tresch, Werner Keil atsticks@java.net @atsticks keilw@java.net @wernerkeil http://java.net/projects/javamoney
  • 2. Bios Anatole Tresch • Consultant - Coach • Software and Framework Architect • Open Source Addicted • Credit Suisse • Specification Lead JSR 354 Anatole Tresch, Werner Keil Introduction to JSR 354 http://java.net/projects/javamoney Werner Keil • Consultant – Coach • Creative Cosmopolitan • Open Source Evangelist • Software Architect • Java Godfather • JCP Executive Committee Member • Eclipse UOMo Project Lead • DevOps Guy • Expert Group JSR 354
  • 3. Agenda • History and Motivation • Overview • Amounts, Currencies • Numeric precision, Rounding • Formatting & Parsing • Currency Conversion • Provider & Extensions • Demo Anatole Tresch, Werner Keil Introduction to JSR 354 http://java.net/projects/javamoney Scope: Platform (SE) Scope: Standalone
  • 5. Earlier Approaches Anatole Tresch, Werner Keil Introduction to JSR 354 http://java.net/projects/javamoney 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. … 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. 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/eaaCa talog/money.html
  • 6. Motivation Anatole Tresch, Werner Keil  Monetary values are a key feature to many applications  The existing java.util.Currency class is strictly a structure used for representing ISO-4217 standard currencies.  No standard value type to represent a monetary amount.  No support for currency arithmetic or conversion.  JDK Formatting features lack of flexibility. Introduction to JSR 354 http://java.net/projects/javamoney
  • 7. Schedule Anatole Tresch, Werner Keil • Targeting 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 • EDR: Beginning of April 2013 Introduction to JSR 354 http://java.net/projects/javamoney
  • 9. Overview on JSR 354 Anatole Tresch, Werner Keil • Core API: javax.money • CurrencyUnit, MonetaryAmount and exceptions • Conversion API: javax.money.conversion • ExchangeRate, CurrencyConverter • Formatting: javax.money.format • LocalizationStyle, ItemFormatter, ItemParser • Provider singleton: javax.money .Monetary • Extensions: javax.money.ext • Region support, Calculations • Reference Implementation: net.java.javamoney.ri • TCK Introduction to JSR 354 http://java.net/projects/javamoney
  • 11. Currencies: What’s all in ISO 4217 Anatole Tresch, Werner Keil • Special Codes • For precious metals (XAU, XAG) • for testing (XTS) • no currency (XXX) • Supranational currencies, e.g. East Caribbean dollar, the CFP franc, the CFA franc. • «Ambiguities»: • CFA franc: West African CFA franc and the Central African CFA franc. Although theoretically separate, the two CFA franc currencies are effectively interchangeable. • Switzerland: CHF, CHE (WIR-EURO), CHW (WIR) • USA: USD, USN (next day), USS (same day) • Unmodeled Aspects: • Different legal acceptance, e.g. Indian Rupees are accepted in Buthan/Nepal, but not vice versa • Minor units 1/100, 1/1000, but also 1/5 (Mauritania, Madagaskar), 0.00000001 (BitCoin) Introduction to JSR 354 http://java.net/projects/javamoney
  • 12. Virtual Currencies Anatole Tresch, Werner Keil • Video Game Currencies (Gold,Gil, Rupees, Credits, Gold Rings, Hearts, Zenny, Potch, Munny, Nuyen…) • 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. • Bitcoin (sign: BTC) is a decentralized digital currency based on an open-source, peer-to-peer internet protocol. It was introduced by a pseudonymous developer named Satoshi Nakamoto in 2009. Introduction to JSR 354 http://java.net/projects/javamoney
  • 13. Limitations of java.util.Currency Anatole Tresch, Werner Keil • No support for historical Currencies • No support for non standard Currencies (e.g. cows or camels) • No support for virtual Currencies (Lindon Dollars, BitCoin, Social Currencies) • No support for custom schemes (e.g. legacy codes) • Only access by currency code, or Locale • No support for special use cases/extensions Introduction to JSR 354 http://java.net/projects/javamoney public interface CurrencyUnit{ public String getCurrencyCode(); public int getNumericCode(); public int getDefaultFractionDigits(); // new methods public String getNamespace(); public boolean isLegalTender(); public boolean isVirtual(); public Long getValidFrom(); public Long getValidUntil(); public <T> T getAttribute( String key, Class<T> type); public Enumeration<String> getAttributeKeys(); public Class<?> getAttributeType( String key); }
  • 14. Monetary Amount Anatole Tresch, Werner Keil • Amount = Number + Currency + Operations • How to represent the numeric amount? • Performant (e.g. for trading) • Precise (e.g. for calculations) • For small numbers (e.g. webshop) • For huge Numbers (e.g. risk calulations, statistics) • Rounding, Precision, Scale Introduction to JSR 354 http://java.net/projects/javamoney Solution: allow different number representations!
  • 15. Monetary Amount (Continued) Anatole Tresch, Werner Keil Introduction to JSR 354 http://java.net/projects/javamoney public interface MonetaryAmount{ public CurrencyUnit getCurrency(); public Class<?> getNumberType(); public <T> T asType(Class<T>); public int intValue(); public int intValueExact(); public long longValue(); public long longValueExact(); […] public MonetaryAmount abs(); public MonetaryAmount min(…); public MonetaryAmount max(…); public MonetaryAmount add(…); public MonetaryAmount subtract(…); public MonetaryAmount divide(…); public MonetaryAmount[] divideAndRemainder(…); public MonetaryAmount divideToIntegralValue(…); public MonetaryAmount remainder(…); public MonetaryAmount multiply(…); public MonetaryAmount with(Number amount); […] public int getScale(); public int getPrecision(); […] public boolean isPositive(); public boolean isPositiveOrZero(); public boolean isNegative(); public boolean isNegativeOrZero(); public boolean lessThan(…); public boolean lessThanOrEqualTo(…); […] } Access Currency and Number part. Algorithmic Operations… Data Representation and Comparison .
  • 17. Types of Numeric Precision Anatole Tresch, Werner Keil • Internal Precision (implied by number representation and arithmetic) • External Precision (rounding applied when a numeric value of an amount is accessed) • Formatting Precision (rounding applied for display and output) • Interoperability Challenges • Different precision/scale • Different numeric representations • Serialization By default only internal rounding is applied automatically. Introduction to JSR 354 http://java.net/projects/javamoney
  • 18. Rounding rounding = Monetary.getRoundingProvider(). getRounding(“Argentina”); MontaryAmount myAmount = …; MonetaryAmount rounded = rounding.round(myAmount); Rounding API Anatole Tresch, Werner Keil • External Rounding and Formatting Rounding can be implemented in many ways, depending on the use cases: • Example for non standard-rounding: Argentina: • 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. Introduction to JSR 354 http://java.net/projects/javamoney public interface Rounding{ public MonetaryAmount round(MonetaryAmount ); } 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
  • 20. Formatting & Parsing Challenges Anatole Tresch, Werner Keil • Different Locale for Translation, Dates, Time, Numbers, Currencies • Additional configuration • Currency Placement, Rounding, Lenient Fractions, Min, Max, legal units, customer group etc. • Natural language support for non-decimal valuations,eg. – Lakhs, Crores (1 Lakh = 100,000, 1 Crore = 100 Lakh) – INR 12,34,56,000.21 is written 12 Crore, 34 Lakh, 56 Thousand Rupees and 21 Paise • Different styles. Introduction to JSR 354 http://java.net/projects/javamoney Define LocalizationStyle and according ItemFormatter/-Parser public class LocalizationStyle implements Serializable { […] public String getId(); public Locale getTranslationLocale(); public Locale getNumberLocale(); public Locale getDateLocale(); public Locale getTimeLocale(); public Map<String, Object> getAttributes() ; public <T> T getAttribute( String key, Class<T> type); public static LocalizationStyle of( Locale locale); public boolean isDefaultStyle() ; […] }
  • 22. Currency Conversion Anatole Tresch, Werner Keil • ExchangeRateType • ExchangeRate: • ExchangeRateType • Source, target currency • Conversion Factor • Validity Range (from/until) • Provider (optional) • Direct/Derived Rate • Attributes • ExchangeRateProvider • CurrencyConverter Introduction to JSR 354 http://java.net/projects/javamoney public interface ExchangeRate { public ExchangeRateType getExchangeRateType(); public CurrencyUnit getSource(); public CurrencyUnit getTarget(); public Number getFactor(); public Long getValidFrom(); public Long getValidUntil(); public boolean isValid(); public String getProvider(); public ExchangeRate[] getExchangeRateChain(); public boolean isDerived(); public boolean isIdentity(); public <T> T getAttribute(String key, Class<T> type); public Enumeration<String> getAttributeKeys(); public Class<?> getAttributeType(String key); } ExchangeRateType rateType = …; CurrencyConverter conv = Monetary.getCurrencyConverter(rateType);
  • 24. Provider: Monetary Singleton Anatole Tresch, Werner Keil • javax.money.Monetary provides access to all components • Loading mechanism is configurable, e.g. • ServiceLoader (default) • CDI • Spring • … Introduction to JSR 354 http://java.net/projects/javamoney public final class Monetary{ public static MonetaryAmountProvider getMonetaryAmountProvider( Class<?> numberClass); public static MonetaryAmountProvider getMonetaryAmountProvider() public static CurrencyUnitProvider getCurrencyUnitProvider(); public static ConversionProvider getConversionProvider(); public static ItemFormatterFactory getItemFormatterFactory(); public static ItemParserFactory getItemParserFactory(); public static RoundingProvider getRoundingProvider(); public static <T> T getExtension(Class<T> extensionType); public static boolean isExtensionAvailable(Class<?> type); public static Enumeration<Class<?>> getLoadedExtensions(); }+Extensions
  • 25. Extensions Anatole Tresch, Werner Keil • Idea: allow registration of additional functionalities into Monetary: • Compound Values • Utilities and Calculation Modules • Regions/Regional Providers • To be discussed: • what extensions should be part of the JSR? • Should extensions by part of this JSR at all? Introduction to JSR 354 http://java.net/projects/javamoney CalculationUtils utils = Monetary.getExtension(CalculationUtils.class); utils.total(…);
  • 26. Demo Anatole Tresch, Werner Keil Introduction to JSR 354 http://java.net/projects/javamoney
  • 27. Q & A Anatole Tresch, Werner Keil Introduction to JSR 354 http://java.net/projects/javamoney
  • 28. Stay Tuned Anatole Tresch, Werner Keil • JSR 354: http://jcp.org • Java.net Project: http://java.net/projects/javamoney • GitHub Project: https://github.com/JavaMoney/javamoney • Eclipse UOMo: http://www.eclipse.org/uomo • Twitter: @jsr354 Introduction to JSR 354 http://java.net/projects/javamoney