Java Reference
In-Depth Information
Other constructors allow you to pass fewer or more arguments. The argument para-
meters can include language, region, and optional variant codes.
Finally, the Locale class has many predefined static instances for some com-
monly used cases. Because the instances are predefined, your code needs to reference
only the static instances. For example, the following example shows how to reference
existing static instances representing fr-FR, ja-JP , and en-US locales:
Locale frenchInFrance = Locale.FRANCE;
Locale japaneseInJapan = Locale.JAPAN;
Locale englishInUS = Locale.US;
Refer to the locale Java API documentation for examples of other static instances.
How It Works
The Locale class gives locale-sensitive classes the context they need to perform
culturally-appropriate data formatting and parsing. Some of the locale-sensitive classes
include the following:
java.text.NumberFormat
java.text.DateFormat
java.util.Calendar
A Locale instance identifies a specific language and can be finely tuned to identi-
fy languages written in a particular script or spoken in a specific world region.
Locale is an important and necessary element for creating anything that depends on
language or regional influences.
The Java Locale class is always being enhanced to provide better support for
modern BCP 47 language tags. BCP 47 defines Best Common Practices for using ISO
standards for language, region, script, and variant identifiers. Although the existing
Locale constructors continue to be compatible with prior versions of the Java plat-
form, the constructors do not support the additional script tags. For example, only the
newer Locale.Builder class and Locale.forLanguageTag() method sup-
port the newer functionality that identifies scripts. This newer class and method were
introduced in Java 7. Because the Locale constructors do not enforce strict BCP 47
compliance, you should avoid the constructors in any new code. Instead, developers
Search WWH ::




Custom Search