esuslogo
 [To advertise Java(tm) Events here, contact joris@esus.com!]
banner

Java™
by example!






New @ Esus.com


  gb  In-house search engine for better results!

  gb  Get updates with the esus.com
newsletter!









  Home 
 Browse Categories 
 Ask a Java Question 
 Help 
  For Java Tips & Tricks, subscribe to the esus.com newsletter!
Search Java Q&A, Links, API's:   adv 

What is a locale?
A locale identifies a particular language and region. Optionally, you can specify a custom parameter called a variant. A locale object is useful for internationalization. For example: in the US the decimal symbol is point whereas in Belgium it's a comma. To format the number correctly to the user, your application must consult the Locale object to determine the current language or region.

Whenever you create a locale object without specifying language or region, you'll get the default one. This one is automatically determined as follows:

 
This code sample is only viewable to esus.com members
Login or become a member!


To get the default locale:

 
This code sample is only viewable to esus.com members
Login or become a member!


You can create your own locale object as follows:

 
This code sample is only viewable to esus.com members
Login or become a member!


Optionally, you can specify a variant:

 
This code sample is only viewable to esus.com members
Login or become a member!


Classes that depend on a language (NumberFormat, DateFormat, ...) or region are called locale-sensitive. Typically, you can call the static method getAvailableLocales on that class to find out the locales that work with that class. A resource bundle (see the category resourcebundles) also makes heavily use on locales, as it needs them to determine the correct class name or properties file.

Once you have a particular locale identified through one of the constructors, you have access to several methods to find out more about that locale. Look at the API for more information. Here's an example:

 
This code sample is only viewable to esus.com members
Login or become a member!


outputs:

 
This code sample is only viewable to esus.com members
Login or become a member!




Further Information
Author of answer: Joris Van den Bogaert

Comments to this answer are only viewable by members. Login or become a member!





Terms of Service | Privacy Policy | Contact

Copyright © 2000-2003 Esus.com - All Rights Reserved 
Java and all Java-based trademarks are trademarks of Sun Microsystems, Inc. Esus.com is independent of Sun Microsystems, Inc. All other trademarks are the sole property of their respective owners.