They serve two very different purposes, as is detailed in their respective API descriptions.
In fact NumberFormat's subclass DecimalFormat uses the Currency class to determine the symbol to use when formatting a value.
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
ankita modi. wrote:We do use NumberFormat class to format currency according to locale,then what is for Currency class ?
There is a lot more to currencies than just formatting. Just for example, every currency has:
1. A symbol: eg, "$"
2. A code: eg, "USD"
3. (Generally, but not always) A country.
4. A format (basically, this is the number of digits used after the decimal point for the smallest unit).
and the JavaCurrency class holds all that information according to the ISO 4217 specification.
One thing I notice it doesn't hold is whether the symbol is used as a prefix or a suffix which, I have to admit, is quite surprising.
Bats fly at night, 'cause they aren't we. And if we tried, we'd hit a tree -- Ogden Nash (or should've been).
Articles by Winston can be found here
That should be fairly straightforward. If you look at the currency API, does it offer you a means of formatting a Number (or primitive data types) as String value, or parsing a String value as a Number?
Note that the Currency class is designed so that there is never more than one Currency instance for any given currency. Therefore, there is no public constructor. As demonstrated in the previous code example, you obtain a Currency instance using the getInstance methods.
What exactly about those sentences do you not understand?
It explains that for every currency (for example US dollars, Euro, etc.) there is exactly one Currency object. The class Currency has no public constructors, so that you cannot create a second Currency object for an existing currency. Instead of a public constructor, there's a getInstance() factory method that returns the Currency object for the currency that you pass to the getInstance() method.