This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Locale Class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Locale Class" Watch "Locale Class" New topic

Locale Class

Duleep Thivanka

Joined: May 23, 2008
Posts: 10
Using Locale's getAvailableLocales() method I can list all locales in Java Virtual Machine.Is there a way to add new Locale to Java Virtual Machine ?.Thank You
Sondre Kval�

Joined: Aug 14, 2008
Posts: 8
Have a look at the implementation of java.util.Locale.getAvailebleLocales() (JSE 5.0):

The class LocaleData has the fully qualified name sun.text.resources.LocaleData and the source code for this is unfortunately no publically available. Browsing through the OpenJDK makes me believe that the list of available locale should be defined at compile-time. If this is correct there is now way of edit this list at run time.

You can however define your own locale using one of the constructors in the Locale class, and use this as input to the java.util.Locale.setDefault(Locale) method (and of course to whatever method that requires a Locale object as input).
Duleep Thivanka

Joined: May 23, 2008
Posts: 10
Thanks for the reply.But I want to install a new locale.How I can do that.setDefault method doesn't work because before that I want to install a new locale.
Paul Clapham

Joined: Oct 14, 2005
Posts: 19691

It should be pretty clear from the API documentation that the Locale class doesn't have any methods to install a new locale.

If you then click on the "Use" button at the top of the documentation page for Locale, that shows you everything in the standard API which uses Locale. You can check for yourself that there's nothing in this long list which installs a new Locale either.

An interesting thing you might notice in the list is that there are methods whose descriptions are like, for example, "Gets the date formatter with the given formatting style for the given locale". That implies that internally a Locale has a whole lot more baggage attached to it -- date formatters, number formatters, collators, and so on. You can't define any of that when you create a new Locale but the built-in Locales do have it.

Even the String class has a toLowerCase(Locale) method which uses the rules of the Locale for lower-casing. You wouldn't have any way of dealing with that, either. So installing a new Locale wouldn't be all that useful any way, since you don't have a way of specifying all those Locale-dependent objects and behaviours.
Duleep Thivanka

Joined: May 23, 2008
Posts: 10
Thanks for your thoughts.
I agree. Here's the link:
subject: Locale Class
It's not a secret anymore!