java.util
Class Currency

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by java.util.Currency
All Implemented Interfaces:
Serializable sample code for java.io.Serializable definition code for java.io.Serializable

public final class Currency
extends Object sample code for java.lang.Object definition code for java.lang.Object
implements Serializable sample code for java.io.Serializable definition code for java.io.Serializable

Represents a currency. Currencies are identified by their ISO 4217 currency codes. See the ISO 4217 maintenance agency for more information, including a table of currency codes.

The class is designed so that there's never more than one Currency instance for any given currency. Therefore, there's no public constructor. You obtain a Currency instance using the getInstance methods.

Since:
1.4
See Also:
Serialized Form

Method Summary
 String sample code for java.lang.String definition code for java.lang.String getCurrencyCode sample code for java.util.Currency.getCurrencyCode() definition code for java.util.Currency.getCurrencyCode() ()
          Gets the ISO 4217 currency code of this currency.
 int getDefaultFractionDigits sample code for java.util.Currency.getDefaultFractionDigits() definition code for java.util.Currency.getDefaultFractionDigits() ()
          Gets the default number of fraction digits used with this currency.
static Currency sample code for java.util.Currency definition code for java.util.Currency getInstance sample code for java.util.Currency.getInstance(java.util.Locale) definition code for java.util.Currency.getInstance(java.util.Locale) (Locale sample code for java.util.Locale definition code for java.util.Locale  locale)
          Returns the Currency instance for the country of the given locale.
static Currency sample code for java.util.Currency definition code for java.util.Currency getInstance sample code for java.util.Currency.getInstance(java.lang.String) definition code for java.util.Currency.getInstance(java.lang.String) (String sample code for java.lang.String definition code for java.lang.String  currencyCode)
          Returns the Currency instance for the given currency code.
 String sample code for java.lang.String definition code for java.lang.String getSymbol sample code for java.util.Currency.getSymbol() definition code for java.util.Currency.getSymbol() ()
          Gets the symbol of this currency for the default locale.
 String sample code for java.lang.String definition code for java.lang.String getSymbol sample code for java.util.Currency.getSymbol(java.util.Locale) definition code for java.util.Currency.getSymbol(java.util.Locale) (Locale sample code for java.util.Locale definition code for java.util.Locale  locale)
          Gets the symbol of this currency for the specified locale.
 String sample code for java.lang.String definition code for java.lang.String toString sample code for java.util.Currency.toString() definition code for java.util.Currency.toString() ()
          Returns the ISO 4217 currency code of this currency.
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
clone sample code for java.lang.Object.clone() definition code for java.lang.Object.clone() , equals sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) , finalize sample code for java.lang.Object.finalize() definition code for java.lang.Object.finalize() , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , hashCode sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 

Method Detail

getInstance sample code for java.util.Currency.getInstance(java.lang.String) definition code for java.util.Currency.getInstance(java.lang.String)

public static Currency sample code for java.util.Currency definition code for java.util.Currency  getInstance(String sample code for java.lang.String definition code for java.lang.String  currencyCode)
Returns the Currency instance for the given currency code.

Parameters:
currencyCode - the ISO 4217 code of the currency
Returns:
the Currency instance for the given currency code
Throws:
NullPointerException sample code for java.lang.NullPointerException definition code for java.lang.NullPointerException - if currencyCode is null
IllegalArgumentException sample code for java.lang.IllegalArgumentException definition code for java.lang.IllegalArgumentException - if currencyCode is not a supported ISO 4217 code.

getInstance sample code for java.util.Currency.getInstance(java.util.Locale) definition code for java.util.Currency.getInstance(java.util.Locale)

public static Currency sample code for java.util.Currency definition code for java.util.Currency  getInstance(Locale sample code for java.util.Locale definition code for java.util.Locale  locale)
Returns the Currency instance for the country of the given locale. The language and variant components of the locale are ignored. The result may vary over time, as countries change their currencies. For example, for the original member countries of the European Monetary Union, the method returns the old national currencies until December 31, 2001, and the Euro from January 1, 2002, local time of the respective countries.

The method returns null for territories that don't have a currency, such as Antarctica.

Parameters:
locale - the locale for whose country a Currency instance is needed
Returns:
the Currency instance for the country of the given locale, or null
Throws:
NullPointerException sample code for java.lang.NullPointerException definition code for java.lang.NullPointerException - if locale or its country code is null
IllegalArgumentException sample code for java.lang.IllegalArgumentException definition code for java.lang.IllegalArgumentException - if the country of the given locale is not a supported ISO 3166 country code.

getCurrencyCode sample code for java.util.Currency.getCurrencyCode() definition code for java.util.Currency.getCurrencyCode()

public String sample code for java.lang.String definition code for java.lang.String  getCurrencyCode()
Gets the ISO 4217 currency code of this currency.

Returns:
the ISO 4217 currency code of this currency.

getSymbol sample code for java.util.Currency.getSymbol() definition code for java.util.Currency.getSymbol()

public String sample code for java.lang.String definition code for java.lang.String  getSymbol()
Gets the symbol of this currency for the default locale. For example, for the US Dollar, the symbol is "$" if the default locale is the US, while for other locales it may be "US$". If no symbol can be determined, the ISO 4217 currency code is returned.

Returns:
the symbol of this currency for the default locale

getSymbol sample code for java.util.Currency.getSymbol(java.util.Locale) definition code for java.util.Currency.getSymbol(java.util.Locale)

public String sample code for java.lang.String definition code for java.lang.String  getSymbol(Locale sample code for java.util.Locale definition code for java.util.Locale  locale)
Gets the symbol of this currency for the specified locale. For example, for the US Dollar, the symbol is "$" if the specified locale is the US, while for other locales it may be "US$". If no symbol can be determined, the ISO 4217 currency code is returned.

Parameters:
locale - the locale for which a display name for this currency is needed
Returns:
the symbol of this currency for the specified locale
Throws:
NullPointerException sample code for java.lang.NullPointerException definition code for java.lang.NullPointerException - if locale is null

getDefaultFractionDigits sample code for java.util.Currency.getDefaultFractionDigits() definition code for java.util.Currency.getDefaultFractionDigits()

public int getDefaultFractionDigits()
Gets the default number of fraction digits used with this currency. For example, the default number of fraction digits for the Euro is 2, while for the Japanese Yen it's 0. In the case of pseudo-currencies, such as IMF Special Drawing Rights, -1 is returned.

Returns:
the default number of fraction digits used with this currency

toString sample code for java.util.Currency.toString() definition code for java.util.Currency.toString()

public String sample code for java.lang.String definition code for java.lang.String  toString()
Returns the ISO 4217 currency code of this currency.

Overrides:
toString sample code for java.lang.Object.toString() definition code for java.lang.Object.toString() in class Object sample code for java.lang.Object definition code for java.lang.Object
Returns:
the ISO 4217 currency code of this currency