Java Reference
In-Depth Information
24.1. Locale
A java.util.Locale object describes a specific placecultural, political, or
geographical. Using a locale, objects can localize their behavior to a
user's expectations. An object that does so is called locale-sensitive. For
example, date formatting can be localized by using the locale-sensitive
DateFormat class (described later in this chapter), so the date written in
the United Kingdom as 26/11/72 would be written 26.11.72 in Iceland, 11/
26/72 in the United States, or 72.26.11 in Latvia.
A single locale represents issues of language, country, and other tradi-
tions. There can be separate locales for U.S. English, U.K. English, Aus-
tralian English, Pakistani English, and so forth. Although the language is
arguably in common for these locales, the customs of date, currency, and
numeric representation vary.
Your code will rarely get or create Locale objects directly but instead will
use the default locale that reflects the user's preference. You typically use
this locale implicitly by getting resources or resource bundles as shown
with other locale-sensitive classes. For example, you get the default cal-
endar object like this:
Calendar now = Calendar.getInstance();
The Calendar class's getInstance method looks up the default locale to con-
figure the calendar object it returns. When you write your own locale-
sensitive classes, you get the default locale from the static getdefault
method of the Locale class.
If you write code that lets a user select a locale, you may need to create
Locale objects. There are three constructors:
public Locale(String language, String country, String variant)
 
Search WWH ::




Custom Search