SlideShare a Scribd company logo
JSR 354: Money and Currency API
Werner Keil | Otávio Santana
@wernerkeil | @otaviojava | @jsr354
https://www.jcp.org/en/jsr/detail?id=354
http://javamoney.org
History and Motivation
Earlier 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
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.
Motivation
> Monetary values are a key feature to many applications
> 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 flexibility
Overview of JSR 354
> Core API: javax.money
 CurrencyUnit, MonetaryAmount
> Conversion API: javax.money.convert
 ExchangeRate, ConversionContext
> Formatting: javax.money.format
 AmountFormatContext, MonetaryAmountFormat
> Reference Implementation: org.javamoney.moneta
> TCK: org.javamoney.tck
/**
* Simplest case create an amount with an ISO currency.
*/
public void forISOCurrencies() {
Money amount = Money.of(1234566.15, "USD"); // using ISO namespace by default
}
/**
* Create an amount using a custom currency.
*/
public void forCustomCurrencies() {
CurrencyUnit currency = Monetary.getCurrency("myCode");
Money amount = Money.of(1234566.15, currency);
}
6 © 2012-2015 JavaMoney contributors
Creating Amounts
Currency Conversion
> ExchangeRateType
> ExchangeRate:
– ConversionContext
– Base, Term currency
– Conversion factor
– Direct/Derived Rates
> ConversionProvider/CurrencyConverter
> MonetaryConversions accessor singleton
public interface ExchangeRate {
public CurrencyUnit getBaseCurrency();
public CurrencyUnit getCurrency();
public NumberValue getFactor();
public ConversionContext getContext();
public List<ExchangeRate> getExchangeRateChain();
public boolean isDerived();
}
7 © 2012-2015 JavaMoney contributors
// Shows accessing exchange rates and doing conversions.
MonetaryAmount amt = Money.of(2000, "EUR");
System.out.println("2000 EUR -(ECB)-> HUF = " +
amt.with(MonetaryConversions.getConversion("HUF", "ECB")));
System.out.println("2000 EUR -(IMF)-> HUF = " +
amt.with(MonetaryConversions.getConversion("HUF", "IMF")));
System.out.println("2000 EUR -(ECB, at 5th Jan 2015)->
HUF = " +
amt.with(MonetaryConversions.getConversion(ConversionQueryBu
ilder.of().setTermCurrency("HUF")
.set(LocalDate.of(2015, 01, 05)).build())));
8 © 2012-2015 JavaMoney contributors
Currency Conversion
Virtual Currencies
> 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 (allegedly Australian tech entrepreneur
Craig Wright) in 2009.
Adopters
Zalando
10 © 2012-2015 JavaMoney contributors
Image: Zalando
Gimme Shelter
Adopt-a-JSR and similar Efforts
11 © 2012-2015 JavaMoney contributors
Links
• JSR 354: https://jcp.org/en/jsr/detail?id=354
• JavaMoney Site: http://javamoney.org
• JavaMoney Shelter: http://javamoney.github.io/shelter.html
• GitHub Organization: https://github.com/JavaMoney/
• Twitter: @jsr354
Demo
javax.money
JSR 354: Money and Currency API - Short Overview

More Related Content

PPTX
JSR 375 - Have you seen Java EE Security API lately? - codemotion Tel Aviv 2015
PDF
The seven more deadly sins of microservices final
PDF
Reactive Principles and Microservices
PPTX
Alfresco/Activiti Modeler Application - Andras Popovics - 2019
PPTX
Building 12-factor Cloud Native Microservices
PPTX
Data stores: beyond relational databases
PDF
Javantura v4 - The power of cloud in professional services company - Ivan Krn...
PDF
Microservices in Scala - theory & practice
JSR 375 - Have you seen Java EE Security API lately? - codemotion Tel Aviv 2015
The seven more deadly sins of microservices final
Reactive Principles and Microservices
Alfresco/Activiti Modeler Application - Andras Popovics - 2019
Building 12-factor Cloud Native Microservices
Data stores: beyond relational databases
Javantura v4 - The power of cloud in professional services company - Ivan Krn...
Microservices in Scala - theory & practice

What's hot (14)

PDF
A Deep Dive into Spring Application Events
PDF
474 Password Not Found
PDF
Single Sign On (SSO) Services with Free/Open Source Software
PDF
Java on Azure
PDF
Introducing Clean Architecture
ODP
Spring cloud for microservices architecture
PPTX
CQRS Evolved - CQRS + Akka.NET
PPTX
Security Testing with Zap
PDF
Microservices Practitioner Summit Jan '15 - Microservice Ecosystems At Scale ...
ODP
Dev ops ci-ap-is-oh-my_security-gone-agile_ut-austin
PDF
Microservices - opportunities, dilemmas and problems
PDF
Building microservices web application using scala & akka
PDF
JavaCro'15 - Service Discovery in OSGi Beyond the JVM using Docker and Consul...
PPTX
Springboot Microservices
A Deep Dive into Spring Application Events
474 Password Not Found
Single Sign On (SSO) Services with Free/Open Source Software
Java on Azure
Introducing Clean Architecture
Spring cloud for microservices architecture
CQRS Evolved - CQRS + Akka.NET
Security Testing with Zap
Microservices Practitioner Summit Jan '15 - Microservice Ecosystems At Scale ...
Dev ops ci-ap-is-oh-my_security-gone-agile_ut-austin
Microservices - opportunities, dilemmas and problems
Building microservices web application using scala & akka
JavaCro'15 - Service Discovery in OSGi Beyond the JVM using Docker and Consul...
Springboot Microservices
Ad

Viewers also liked (16)

PDF
The Development of Online Courses
PDF
Six Sigma Certification Process
PDF
Levi Plaza Fountain Return Line 6 PP
PPT
Social studies
PPTX
Questionnaire analysis
DOCX
resume
PDF
Training for Residents and Community Groups
PPTX
MELNHE overview 2016
PPTX
Microservices in production
PDF
Membayar Hutang Sebesar Gunung
PPTX
PRESENTATION ON PAKISTAN HOCKEY
PPTX
Java v/s .NET - Which is Better?
PDF
B sc (hons)(arch) asian architecture arc60403 project aug 2015 (4)
PDF
05 Machine Learning - Supervised Fisher Classifier
PPTX
Cloud fest 2012_jc02
The Development of Online Courses
Six Sigma Certification Process
Levi Plaza Fountain Return Line 6 PP
Social studies
Questionnaire analysis
resume
Training for Residents and Community Groups
MELNHE overview 2016
Microservices in production
Membayar Hutang Sebesar Gunung
PRESENTATION ON PAKISTAN HOCKEY
Java v/s .NET - Which is Better?
B sc (hons)(arch) asian architecture arc60403 project aug 2015 (4)
05 Machine Learning - Supervised Fisher Classifier
Cloud fest 2012_jc02
Ad

Similar to JSR 354: Money and Currency API - Short Overview (20)

PPTX
JSR354 Utrecht JUG 20171027
PDF
Adopt JSR 354
PDF
JSR 354 LJC-Hackday
PDF
JSR 354 Hackday - What you can do...
PDF
Go for the Money - JSR 354
PPTX
Introducing JSR 354 The Money & Currency API
PDF
Introduction to JSR 354 (Currency and Money) by Anatole Tresch, Werner Keil
PDF
Cooking your Ravioli "al dente" with Hexagonal Architecture
PPTX
JSR 354 - Money and Currency API
PPTX
Introduction to JSR 354 (Currency and Money) by Anatole Tresch
PDF
Beyond MVC: from Model to Domain
PDF
Web automation with #d8rules (European Drupal Days 2015)
PDF
Living in the Matrix with Bytecode Manipulation
PPT
JSR 354 - Money and Currency API for Java
PPTX
Money, Money, Money, can be funny with JSR 354 (DWX 2019)
PDF
Dutch PHP Conference 2015 - The quest for global design principles
PDF
JAZOON'13 - Anatole Tresch - Go for the money (JSR 354) !
PDF
Beyond MVC: from Model to Domain
PPTX
My-currency_Rajat_Kum convertor PPT.pptx
PPTX
How to Build & Develop Responsive Open Learning Environments with the ROLE SDK
JSR354 Utrecht JUG 20171027
Adopt JSR 354
JSR 354 LJC-Hackday
JSR 354 Hackday - What you can do...
Go for the Money - JSR 354
Introducing JSR 354 The Money & Currency API
Introduction to JSR 354 (Currency and Money) by Anatole Tresch, Werner Keil
Cooking your Ravioli "al dente" with Hexagonal Architecture
JSR 354 - Money and Currency API
Introduction to JSR 354 (Currency and Money) by Anatole Tresch
Beyond MVC: from Model to Domain
Web automation with #d8rules (European Drupal Days 2015)
Living in the Matrix with Bytecode Manipulation
JSR 354 - Money and Currency API for Java
Money, Money, Money, can be funny with JSR 354 (DWX 2019)
Dutch PHP Conference 2015 - The quest for global design principles
JAZOON'13 - Anatole Tresch - Go for the money (JSR 354) !
Beyond MVC: from Model to Domain
My-currency_Rajat_Kum convertor PPT.pptx
How to Build & Develop Responsive Open Learning Environments with the ROLE SDK

More from Werner Keil (20)

PPTX
Securing eHealth, eGovernment and eBanking with Java - DWX '21
PPTX
OpenDDR and Jakarta MVC - JavaLand 2021
PPTX
How JSR 385 could have Saved the Mars Climate Orbiter - Zurich IoT Day 2021
PPTX
OpenDDR and Jakarta MVC - Java2Days 2020 Virtual
PPTX
NoSQL Endgame - Java2Days 2020 Virtual
PPTX
JCON 2020: Mobile Java Web Applications with MVC and OpenDDR
PPTX
How JSR 385 could have Saved the Mars Climate Orbiter - JFokus 2020
PPTX
Money, Money, Money, can be funny with JSR 354 (Devoxx BE)
PPTX
NoSQL: The first New Jakarta EE Specification (DWX 2019)
PPTX
How JSR 385 could have Saved the Mars Climate Orbiter - Adopt-a-JSR Day
PPTX
JNoSQL: The Definitive Solution for Java and NoSQL Databases
PPTX
Eclipse JNoSQL: The Definitive Solution for Java and NoSQL Databases
PPTX
Physikal - Using Kotlin for Clean Energy - KUG Munich
PPTX
Physikal - JSR 363 and Kotlin for Clean Energy - Java2Days 2017
PPTX
Performance Monitoring for the Cloud - Java2Days 2017
PPTX
Eclipse Science F2F 2016 - JSR 363
PPTX
Java2Days - Security for JavaEE and the Cloud
PPTX
Apache DeviceMap - Web-Dev-BBQ Stuttgart
PPTX
The First IoT JSR: Units of Measurement - JUG Berlin-Brandenburg
PPTX
JavaLand: Quantified Social - Fitness-Geräte und -Portale mit Agorava
Securing eHealth, eGovernment and eBanking with Java - DWX '21
OpenDDR and Jakarta MVC - JavaLand 2021
How JSR 385 could have Saved the Mars Climate Orbiter - Zurich IoT Day 2021
OpenDDR and Jakarta MVC - Java2Days 2020 Virtual
NoSQL Endgame - Java2Days 2020 Virtual
JCON 2020: Mobile Java Web Applications with MVC and OpenDDR
How JSR 385 could have Saved the Mars Climate Orbiter - JFokus 2020
Money, Money, Money, can be funny with JSR 354 (Devoxx BE)
NoSQL: The first New Jakarta EE Specification (DWX 2019)
How JSR 385 could have Saved the Mars Climate Orbiter - Adopt-a-JSR Day
JNoSQL: The Definitive Solution for Java and NoSQL Databases
Eclipse JNoSQL: The Definitive Solution for Java and NoSQL Databases
Physikal - Using Kotlin for Clean Energy - KUG Munich
Physikal - JSR 363 and Kotlin for Clean Energy - Java2Days 2017
Performance Monitoring for the Cloud - Java2Days 2017
Eclipse Science F2F 2016 - JSR 363
Java2Days - Security for JavaEE and the Cloud
Apache DeviceMap - Web-Dev-BBQ Stuttgart
The First IoT JSR: Units of Measurement - JUG Berlin-Brandenburg
JavaLand: Quantified Social - Fitness-Geräte und -Portale mit Agorava

Recently uploaded (20)

PDF
How AI/LLM recommend to you ? GDG meetup 16 Aug by Fariman Guliev
PDF
iTop VPN 6.5.0 Crack + License Key 2025 (Premium Version)
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PPTX
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Download FL Studio Crack Latest version 2025 ?
PPTX
assetexplorer- product-overview - presentation
PDF
Salesforce Agentforce AI Implementation.pdf
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Cost to Outsource Software Development in 2025
PDF
17 Powerful Integrations Your Next-Gen MLM Software Needs
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PDF
iTop VPN Crack Latest Version Full Key 2025
PPTX
WiFi Honeypot Detecscfddssdffsedfseztor.pptx
PPTX
Patient Appointment Booking in Odoo with online payment
PDF
Nekopoi APK 2025 free lastest update
PPTX
Oracle Fusion HCM Cloud Demo for Beginners
PPTX
Reimagine Home Health with the Power of Agentic AI​
How AI/LLM recommend to you ? GDG meetup 16 Aug by Fariman Guliev
iTop VPN 6.5.0 Crack + License Key 2025 (Premium Version)
Design an Analysis of Algorithms II-SECS-1021-03
Odoo Companies in India – Driving Business Transformation.pdf
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Download FL Studio Crack Latest version 2025 ?
assetexplorer- product-overview - presentation
Salesforce Agentforce AI Implementation.pdf
CHAPTER 2 - PM Management and IT Context
Cost to Outsource Software Development in 2025
17 Powerful Integrations Your Next-Gen MLM Software Needs
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
iTop VPN Crack Latest Version Full Key 2025
WiFi Honeypot Detecscfddssdffsedfseztor.pptx
Patient Appointment Booking in Odoo with online payment
Nekopoi APK 2025 free lastest update
Oracle Fusion HCM Cloud Demo for Beginners
Reimagine Home Health with the Power of Agentic AI​

JSR 354: Money and Currency API - Short Overview

  • 1. JSR 354: Money and Currency API Werner Keil | Otávio Santana @wernerkeil | @otaviojava | @jsr354 https://www.jcp.org/en/jsr/detail?id=354 http://javamoney.org
  • 3. Earlier 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 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.
  • 4. Motivation > Monetary values are a key feature to many applications > 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 flexibility
  • 5. Overview of JSR 354 > Core API: javax.money  CurrencyUnit, MonetaryAmount > Conversion API: javax.money.convert  ExchangeRate, ConversionContext > Formatting: javax.money.format  AmountFormatContext, MonetaryAmountFormat > Reference Implementation: org.javamoney.moneta > TCK: org.javamoney.tck
  • 6. /** * Simplest case create an amount with an ISO currency. */ public void forISOCurrencies() { Money amount = Money.of(1234566.15, "USD"); // using ISO namespace by default } /** * Create an amount using a custom currency. */ public void forCustomCurrencies() { CurrencyUnit currency = Monetary.getCurrency("myCode"); Money amount = Money.of(1234566.15, currency); } 6 © 2012-2015 JavaMoney contributors Creating Amounts
  • 7. Currency Conversion > ExchangeRateType > ExchangeRate: – ConversionContext – Base, Term currency – Conversion factor – Direct/Derived Rates > ConversionProvider/CurrencyConverter > MonetaryConversions accessor singleton public interface ExchangeRate { public CurrencyUnit getBaseCurrency(); public CurrencyUnit getCurrency(); public NumberValue getFactor(); public ConversionContext getContext(); public List<ExchangeRate> getExchangeRateChain(); public boolean isDerived(); } 7 © 2012-2015 JavaMoney contributors
  • 8. // Shows accessing exchange rates and doing conversions. MonetaryAmount amt = Money.of(2000, "EUR"); System.out.println("2000 EUR -(ECB)-> HUF = " + amt.with(MonetaryConversions.getConversion("HUF", "ECB"))); System.out.println("2000 EUR -(IMF)-> HUF = " + amt.with(MonetaryConversions.getConversion("HUF", "IMF"))); System.out.println("2000 EUR -(ECB, at 5th Jan 2015)-> HUF = " + amt.with(MonetaryConversions.getConversion(ConversionQueryBu ilder.of().setTermCurrency("HUF") .set(LocalDate.of(2015, 01, 05)).build()))); 8 © 2012-2015 JavaMoney contributors Currency Conversion
  • 9. Virtual Currencies > 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 (allegedly Australian tech entrepreneur Craig Wright) in 2009.
  • 10. Adopters Zalando 10 © 2012-2015 JavaMoney contributors Image: Zalando
  • 11. Gimme Shelter Adopt-a-JSR and similar Efforts 11 © 2012-2015 JavaMoney contributors
  • 12. Links • JSR 354: https://jcp.org/en/jsr/detail?id=354 • JavaMoney Site: http://javamoney.org • JavaMoney Shelter: http://javamoney.github.io/shelter.html • GitHub Organization: https://github.com/JavaMoney/ • Twitter: @jsr354