Java Doc for Locale.java in  » 6.0-JDK-Core » Collections-Jar-Zip-Logging-regex » java » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Home
Java Source Code / Java Documentation
1.6.0 JDK Core
2.6.0 JDK Modules
3.6.0 JDK Modules com.sun
4.6.0 JDK Modules com.sun.java
5.6.0 JDK Modules sun
6.6.0 JDK Platform
7.Ajax
8.Apache Harmony Java SE
9.Aspect oriented
10.Authentication Authorization
11.Blogger System
12.Build
13.Byte Code
14.Cache
15.Chart
16.Chat
17.Code Analyzer
18.Collaboration
19.Content Management System
20.Database Client
21.Database DBMS
22.Database JDBC Connection Pool
23.Database ORM
24.Development
25.EJB Server
26.ERP CRM Financial
27.ESB
28.Forum
29.Game
30.GIS
31.Graphic 3D
32.Graphic Library
33.Groupware
34.HTML Parser
35.IDE
36.IDE Eclipse
37.IDE Netbeans
38.Installer
39.Internationalization Localization
40.Inversion of Control
41.Issue Tracking
42.J2EE
43.J2ME
44.JBoss
45.JMS
46.JMX
47.Library
48.Mail Clients
49.Music
50.Net
51.Parser
52.PDF
53.Portal
54.Profiler
55.Project Management
56.Report
57.RSS RDF
58.Rule Engine
59.Science
60.Scripting
61.Search Engine
62.Security
63.Sevlet Container
64.Source Control
65.Swing Library
66.Template Engine
67.Test Coverage
68.Testing
69.UML
70.Web Crawler
71.Web Framework
72.Web Mail
73.Web Server
74.Web Services
75.Web Services apache cxf 2.2.6
76.Web Services AXIS2
77.Wiki Engine
78.Workflow Engines
79.XML
80.XML UI
Java Source Code / Java Documentation » 6.0 JDK Core » Collections Jar Zip Logging regex » java.util 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   java.util.Locale

Locale
final public class Locale implements Cloneable,Serializable(Code)
A Locale object represents a specific geographical, political, or cultural region. An operation that requires a Locale to perform its task is called locale-sensitive and uses the Locale to tailor information for the user. For example, displaying a number is a locale-sensitive operation--the number should be formatted according to the customs/conventions of the user's native country, region, or culture.

Create a Locale object using the constructors in this class:

 Locale(String language)
 Locale(String language, String country)
 Locale(String language, String country, String variant)
 
The language argument is a valid ISO Language Code. These codes are the lower-case, two-letter codes as defined by ISO-639. You can find a full list of these codes at a number of sites, such as:
http://www.loc.gov/standards/iso639-2/php/English_list.php

The country argument is a valid ISO Country Code. These codes are the upper-case, two-letter codes as defined by ISO-3166. You can find a full list of these codes at a number of sites, such as:
http://www.iso.ch/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/list-en1.html

The variant argument is a vendor or browser-specific code. For example, use WIN for Windows, MAC for Macintosh, and POSIX for POSIX. Where there are two variants, separate them with an underscore, and put the most important one first. For example, a Traditional Spanish collation might construct a locale with parameters for language, country and variant as: "es", "ES", "Traditional_WIN".

Because a Locale object is just an identifier for a region, no validity check is performed when you construct a Locale. If you want to see whether particular resources are available for the Locale you construct, you must query those resources. For example, ask the NumberFormat for the locales it supports using its getAvailableLocales method.
Note: When you ask for a resource for a particular locale, you get back the best available match, not necessarily precisely what you asked for. For more information, look at ResourceBundle .

The Locale class provides a number of convenient constants that you can use to create Locale objects for commonly used locales. For example, the following creates a Locale object for the United States:

 Locale.US
 

Once you've created a Locale you can query it for information about itself. Use getCountry to get the ISO Country Code and getLanguage to get the ISO Language Code. You can use getDisplayCountry to get the name of the country suitable for displaying to the user. Similarly, you can use getDisplayLanguage to get the name of the language suitable for displaying to the user. Interestingly, the getDisplayXXX methods are themselves locale-sensitive and have two versions: one that uses the default locale and one that uses the locale specified as an argument.

The Java Platform provides a number of classes that perform locale-sensitive operations. For example, the NumberFormat class formats numbers, currency, or percentages in a locale-sensitive manner. Classes such as NumberFormat have a number of convenience methods for creating a default object of that type. For example, the NumberFormat class provides these three convenience methods for creating a default NumberFormat object:

 NumberFormat.getInstance()
 NumberFormat.getCurrencyInstance()
 NumberFormat.getPercentInstance()
 
These methods have two variants; one with an explicit locale and one without; the latter using the default locale.
 NumberFormat.getInstance(myLocale)
 NumberFormat.getCurrencyInstance(myLocale)
 NumberFormat.getPercentInstance(myLocale)
 
A Locale is the mechanism for identifying the kind of object (NumberFormat) that you would like to get. The locale is just a mechanism for identifying objects, not a container for the objects themselves.
See Also:   ResourceBundle
See Also:   java.text.Format
See Also:   java.text.NumberFormat
See Also:   java.text.Collator
author:
   Mark Davis
since:
   1.1


Field Summary
final public static  LocaleCANADA
     Useful constant for country.
final public static  LocaleCANADA_FRENCH
     Useful constant for country.
final public static  LocaleCHINA
     Useful constant for country.
final public static  LocaleCHINESE
     Useful constant for language.
final public static  LocaleENGLISH
     Useful constant for language.
final public static  LocaleFRANCE
     Useful constant for country.
final public static  LocaleFRENCH
     Useful constant for language.
final public static  LocaleGERMAN
     Useful constant for language.
final public static  LocaleGERMANY
     Useful constant for country.
final public static  LocaleITALIAN
     Useful constant for language.
final public static  LocaleITALY
     Useful constant for country.
final public static  LocaleJAPAN
     Useful constant for country.
final public static  LocaleJAPANESE
     Useful constant for language.
final public static  LocaleKOREA
     Useful constant for country.
final public static  LocaleKOREAN
     Useful constant for language.
final public static  LocalePRC
     Useful constant for country.
final public static  LocaleROOT
     Useful constant for the root locale.
final public static  LocaleSIMPLIFIED_CHINESE
     Useful constant for language.
final public static  LocaleTAIWAN
     Useful constant for country.
final public static  LocaleTRADITIONAL_CHINESE
     Useful constant for language.
final public static  LocaleUK
     Useful constant for country.
final public static  LocaleUS
     Useful constant for country.
final static  longserialVersionUID
    

Constructor Summary
public  Locale(String language, String country, String variant)
     Construct a locale from language, country, variant. NOTE: ISO 639 is not a stable standard; some of the language codes it defines (specifically iw, ji, and in) have changed.
public  Locale(String language, String country)
     Construct a locale from language, country. NOTE: ISO 639 is not a stable standard; some of the language codes it defines (specifically iw, ji, and in) have changed.
public  Locale(String language)
     Construct a locale from a language code. NOTE: ISO 639 is not a stable standard; some of the language codes it defines (specifically iw, ji, and in) have changed.

Method Summary
public  Objectclone()
    
public  booleanequals(Object obj)
     Returns true if this Locale is equal to another object.
public static  Locale[]getAvailableLocales()
     Returns an array of all installed locales. The returned array represents the union of locales supported by the Java runtime environment and by installed java.util.spi.LocaleServiceProvider LocaleServiceProvider implementations.
public  StringgetCountry()
     Returns the country/region code for this locale, which will either be the empty string or an uppercase ISO 3166 2-letter code.
public static  LocalegetDefault()
     Gets the current value of the default locale for this instance of the Java Virtual Machine.

The Java Virtual Machine sets the default locale during startup based on the host environment.

final public  StringgetDisplayCountry()
     Returns a name for the locale's country that is appropriate for display to the user. If possible, the name returned will be localized for the default locale. For example, if the locale is fr_FR and the default locale is en_US, getDisplayCountry() will return "France"; if the locale is en_US and the default locale is fr_FR, getDisplayCountry() will return "Etats-Unis". If the name returned cannot be localized for the default locale, (say, we don't have a Japanese name for Croatia), this function falls back on the English name, and uses the ISO code as a last-resort value.
public  StringgetDisplayCountry(Locale inLocale)
     Returns a name for the locale's country that is appropriate for display to the user. If possible, the name returned will be localized according to inLocale. For example, if the locale is fr_FR and inLocale is en_US, getDisplayCountry() will return "France"; if the locale is en_US and inLocale is fr_FR, getDisplayCountry() will return "Etats-Unis". If the name returned cannot be localized according to inLocale. (say, we don't have a Japanese name for Croatia), this function falls back on the English name, and finally on the ISO code as a last-resort value.
final public  StringgetDisplayLanguage()
     Returns a name for the locale's language that is appropriate for display to the user. If possible, the name returned will be localized for the default locale. For example, if the locale is fr_FR and the default locale is en_US, getDisplayLanguage() will return "French"; if the locale is en_US and the default locale is fr_FR, getDisplayLanguage() will return "anglais". If the name returned cannot be localized for the default locale, (say, we don't have a Japanese name for Croatian), this function falls back on the English name, and uses the ISO code as a last-resort value.
public  StringgetDisplayLanguage(Locale inLocale)
     Returns a name for the locale's language that is appropriate for display to the user. If possible, the name returned will be localized according to inLocale. For example, if the locale is fr_FR and inLocale is en_US, getDisplayLanguage() will return "French"; if the locale is en_US and inLocale is fr_FR, getDisplayLanguage() will return "anglais". If the name returned cannot be localized according to inLocale, (say, we don't have a Japanese name for Croatian), this function falls back on the English name, and finally on the ISO code as a last-resort value.
final public  StringgetDisplayName()
     Returns a name for the locale that is appropriate for display to the user.
public  StringgetDisplayName(Locale inLocale)
     Returns a name for the locale that is appropriate for display to the user.
final public  StringgetDisplayVariant()
     Returns a name for the locale's variant code that is appropriate for display to the user.
public  StringgetDisplayVariant(Locale inLocale)
     Returns a name for the locale's variant code that is appropriate for display to the user.
public  StringgetISO3Country()
     Returns a three-letter abbreviation for this locale's country.
public  StringgetISO3Language()
     Returns a three-letter abbreviation for this locale's language.
public static  String[]getISOCountries()
     Returns a list of all 2-letter country codes defined in ISO 3166.
public static  String[]getISOLanguages()
     Returns a list of all 2-letter language codes defined in ISO 639.
static  LocalegetInstance(String language, String country, String variant)
     Returns a Locale constructed from the given language, country and variant.
public  StringgetLanguage()
     Returns the language code for this locale, which will either be the empty string or a lowercase ISO 639 code.

NOTE: ISO 639 is not a stable standard-- some languages' codes have changed. Locale's constructor recognizes both the new and the old codes for the languages whose codes have changed, but this function always returns the old code.

public  StringgetVariant()
     Returns the variant code for this locale.
public  inthashCode()
     Override hashCode.
public static synchronized  voidsetDefault(Locale newLocale)
     Sets the default locale for this instance of the Java Virtual Machine. This does not affect the host locale.

If there is a security manager, its checkPermission method is called with a PropertyPermission("user.language", "write") permission before the default locale is changed.

The Java Virtual Machine sets the default locale during startup based on the host environment.

final public  StringtoString()
     Getter for the programmatic name of the entire locale, with the language, country and variant separated by underbars.

Field Detail
CANADA
final public static Locale CANADA(Code)
Useful constant for country.



CANADA_FRENCH
final public static Locale CANADA_FRENCH(Code)
Useful constant for country.



CHINA
final public static Locale CHINA(Code)
Useful constant for country.



CHINESE
final public static Locale CHINESE(Code)
Useful constant for language.



ENGLISH
final public static Locale ENGLISH(Code)
Useful constant for language.



FRANCE
final public static Locale FRANCE(Code)
Useful constant for country.



FRENCH
final public static Locale FRENCH(Code)
Useful constant for language.



GERMAN
final public static Locale GERMAN(Code)
Useful constant for language.



GERMANY
final public static Locale GERMANY(Code)
Useful constant for country.



ITALIAN
final public static Locale ITALIAN(Code)
Useful constant for language.



ITALY
final public static Locale ITALY(Code)
Useful constant for country.



JAPAN
final public static Locale JAPAN(Code)
Useful constant for country.



JAPANESE
final public static Locale JAPANESE(Code)
Useful constant for language.



KOREA
final public static Locale KOREA(Code)
Useful constant for country.



KOREAN
final public static Locale KOREAN(Code)
Useful constant for language.



PRC
final public static Locale PRC(Code)
Useful constant for country.



ROOT
final public static Locale ROOT(Code)
Useful constant for the root locale. The root locale is the locale whose language, country, and variant are empty ("") strings. This is regarded as the base locale of all locales, and is used as the language/country neutral locale for the locale sensitive operations.
since:
   1.6



SIMPLIFIED_CHINESE
final public static Locale SIMPLIFIED_CHINESE(Code)
Useful constant for language.



TAIWAN
final public static Locale TAIWAN(Code)
Useful constant for country.



TRADITIONAL_CHINESE
final public static Locale TRADITIONAL_CHINESE(Code)
Useful constant for language.



UK
final public static Locale UK(Code)
Useful constant for country.



US
final public static Locale US(Code)
Useful constant for country.



serialVersionUID
final static long serialVersionUID(Code)
serialization ID




Constructor Detail
Locale
public Locale(String language, String country, String variant)(Code)
Construct a locale from language, country, variant. NOTE: ISO 639 is not a stable standard; some of the language codes it defines (specifically iw, ji, and in) have changed. This constructor accepts both the old codes (iw, ji, and in) and the new codes (he, yi, and id), but all other API on Locale will return only the OLD codes.
Parameters:
  language - lowercase two-letter ISO-639 code.
Parameters:
  country - uppercase two-letter ISO-3166 code.
Parameters:
  variant - vendor and browser specific code. See class description.
exception:
  NullPointerException - thrown if any argument is null.



Locale
public Locale(String language, String country)(Code)
Construct a locale from language, country. NOTE: ISO 639 is not a stable standard; some of the language codes it defines (specifically iw, ji, and in) have changed. This constructor accepts both the old codes (iw, ji, and in) and the new codes (he, yi, and id), but all other API on Locale will return only the OLD codes.
Parameters:
  language - lowercase two-letter ISO-639 code.
Parameters:
  country - uppercase two-letter ISO-3166 code.
exception:
  NullPointerException - thrown if either argument is null.



Locale
public Locale(String language)(Code)
Construct a locale from a language code. NOTE: ISO 639 is not a stable standard; some of the language codes it defines (specifically iw, ji, and in) have changed. This constructor accepts both the old codes (iw, ji, and in) and the new codes (he, yi, and id), but all other API on Locale will return only the OLD codes.
Parameters:
  language - lowercase two-letter ISO-639 code.
exception:
  NullPointerException - thrown if argument is null.
since:
   1.4




Method Detail
clone
public Object clone()(Code)
Overrides Cloneable



equals
public boolean equals(Object obj)(Code)
Returns true if this Locale is equal to another object. A Locale is deemed equal to another Locale with identical language, country, and variant, and unequal to all other objects. true if this Locale is equal to the specified object.



getAvailableLocales
public static Locale[] getAvailableLocales()(Code)
Returns an array of all installed locales. The returned array represents the union of locales supported by the Java runtime environment and by installed java.util.spi.LocaleServiceProvider LocaleServiceProvider implementations. It must contain at least a Locale instance equal to java.util.Locale.US Locale.US . An array of installed locales.



getCountry
public String getCountry()(Code)
Returns the country/region code for this locale, which will either be the empty string or an uppercase ISO 3166 2-letter code.
See Also:   Locale.getDisplayCountry



getDefault
public static Locale getDefault()(Code)
Gets the current value of the default locale for this instance of the Java Virtual Machine.

The Java Virtual Machine sets the default locale during startup based on the host environment. It is used by many locale-sensitive methods if no locale is explicitly specified. It can be changed using the Locale.setDefault(java.util.Locale) setDefault method. the default locale for this instance of the Java Virtual Machine




getDisplayCountry
final public String getDisplayCountry()(Code)
Returns a name for the locale's country that is appropriate for display to the user. If possible, the name returned will be localized for the default locale. For example, if the locale is fr_FR and the default locale is en_US, getDisplayCountry() will return "France"; if the locale is en_US and the default locale is fr_FR, getDisplayCountry() will return "Etats-Unis". If the name returned cannot be localized for the default locale, (say, we don't have a Japanese name for Croatia), this function falls back on the English name, and uses the ISO code as a last-resort value. If the locale doesn't specify a country, this function returns the empty string.



getDisplayCountry
public String getDisplayCountry(Locale inLocale)(Code)
Returns a name for the locale's country that is appropriate for display to the user. If possible, the name returned will be localized according to inLocale. For example, if the locale is fr_FR and inLocale is en_US, getDisplayCountry() will return "France"; if the locale is en_US and inLocale is fr_FR, getDisplayCountry() will return "Etats-Unis". If the name returned cannot be localized according to inLocale. (say, we don't have a Japanese name for Croatia), this function falls back on the English name, and finally on the ISO code as a last-resort value. If the locale doesn't specify a country, this function returns the empty string.
exception:
  NullPointerException - if inLocale is null



getDisplayLanguage
final public String getDisplayLanguage()(Code)
Returns a name for the locale's language that is appropriate for display to the user. If possible, the name returned will be localized for the default locale. For example, if the locale is fr_FR and the default locale is en_US, getDisplayLanguage() will return "French"; if the locale is en_US and the default locale is fr_FR, getDisplayLanguage() will return "anglais". If the name returned cannot be localized for the default locale, (say, we don't have a Japanese name for Croatian), this function falls back on the English name, and uses the ISO code as a last-resort value. If the locale doesn't specify a language, this function returns the empty string.



getDisplayLanguage
public String getDisplayLanguage(Locale inLocale)(Code)
Returns a name for the locale's language that is appropriate for display to the user. If possible, the name returned will be localized according to inLocale. For example, if the locale is fr_FR and inLocale is en_US, getDisplayLanguage() will return "French"; if the locale is en_US and inLocale is fr_FR, getDisplayLanguage() will return "anglais". If the name returned cannot be localized according to inLocale, (say, we don't have a Japanese name for Croatian), this function falls back on the English name, and finally on the ISO code as a last-resort value. If the locale doesn't specify a language, this function returns the empty string.
exception:
  NullPointerException - if inLocale is null



getDisplayName
final public String getDisplayName()(Code)
Returns a name for the locale that is appropriate for display to the user. This will be the values returned by getDisplayLanguage(), getDisplayCountry(), and getDisplayVariant() assembled into a single string. The display name will have one of the following forms:

language (country, variant)

language (country)

language (variant)

country (variant)

language

country

variant

depending on which fields are specified in the locale. If the language, country, and variant fields are all empty, this function returns the empty string.



getDisplayName
public String getDisplayName(Locale inLocale)(Code)
Returns a name for the locale that is appropriate for display to the user. This will be the values returned by getDisplayLanguage(), getDisplayCountry(), and getDisplayVariant() assembled into a single string. The display name will have one of the following forms:

language (country, variant)

language (country)

language (variant)

country (variant)

language

country

variant

depending on which fields are specified in the locale. If the language, country, and variant fields are all empty, this function returns the empty string.
exception:
  NullPointerException - if inLocale is null



getDisplayVariant
final public String getDisplayVariant()(Code)
Returns a name for the locale's variant code that is appropriate for display to the user. If possible, the name will be localized for the default locale. If the locale doesn't specify a variant code, this function returns the empty string.



getDisplayVariant
public String getDisplayVariant(Locale inLocale)(Code)
Returns a name for the locale's variant code that is appropriate for display to the user. If possible, the name will be localized for inLocale. If the locale doesn't specify a variant code, this function returns the empty string.
exception:
  NullPointerException - if inLocale is null



getISO3Country
public String getISO3Country() throws MissingResourceException(Code)
Returns a three-letter abbreviation for this locale's country. If the locale doesn't specify a country, this will be the empty string. Otherwise, this will be an uppercase ISO 3166 3-letter country code. The ISO 3166-2 country codes can be found on-line at http://www.davros.org/misc/iso3166.txt.
exception:
  MissingResourceException - Throws MissingResourceException if thethree-letter country abbreviation is not available for this locale.



getISO3Language
public String getISO3Language() throws MissingResourceException(Code)
Returns a three-letter abbreviation for this locale's language. If the locale doesn't specify a language, this will be the empty string. Otherwise, this will be a lowercase ISO 639-2/T language code. The ISO 639-2 language codes can be found on-line at http://www.loc.gov/standards/iso639-2/englangn.html.
exception:
  MissingResourceException - Throws MissingResourceException if thethree-letter language abbreviation is not available for this locale.



getISOCountries
public static String[] getISOCountries()(Code)
Returns a list of all 2-letter country codes defined in ISO 3166. Can be used to create Locales.



getISOLanguages
public static String[] getISOLanguages()(Code)
Returns a list of all 2-letter language codes defined in ISO 639. Can be used to create Locales. [NOTE: ISO 639 is not a stable standard-- some languages' codes have changed. The list this function returns includes both the new and the old codes for the languages whose codes have changed.]



getInstance
static Locale getInstance(String language, String country, String variant)(Code)
Returns a Locale constructed from the given language, country and variant. If the same Locale instance is available in the cache, then that instance is returned. Otherwise, a new Locale instance is created and cached.
Parameters:
  language - lowercase two-letter ISO-639 code.
Parameters:
  country - uppercase two-letter ISO-3166 code.
Parameters:
  variant - vendor and browser specific code. See class description. the Locale instance requested
exception:
  NullPointerException - if any argument is null.



getLanguage
public String getLanguage()(Code)
Returns the language code for this locale, which will either be the empty string or a lowercase ISO 639 code.

NOTE: ISO 639 is not a stable standard-- some languages' codes have changed. Locale's constructor recognizes both the new and the old codes for the languages whose codes have changed, but this function always returns the old code. If you want to check for a specific language whose code has changed, don't do

 
 if (locale.getLanguage().equals("he")) 
 ... 
 
Instead, do
 
 if (locale.getLanguage().equals(new Locale("he", "", "").getLanguage())) 
 ...

See Also:   Locale.getDisplayLanguage



getVariant
public String getVariant()(Code)
Returns the variant code for this locale.
See Also:   Locale.getDisplayVariant



hashCode
public int hashCode()(Code)
Override hashCode. Since Locales are often used in hashtables, caches the value for speed.



setDefault
public static synchronized void setDefault(Locale newLocale)(Code)
Sets the default locale for this instance of the Java Virtual Machine. This does not affect the host locale.

If there is a security manager, its checkPermission method is called with a PropertyPermission("user.language", "write") permission before the default locale is changed.

The Java Virtual Machine sets the default locale during startup based on the host environment. It is used by many locale-sensitive methods if no locale is explicitly specified.

Since changing the default locale may affect many different areas of functionality, this method should only be used if the caller is prepared to reinitialize locale-sensitive code running within the same Java Virtual Machine.
throws:
  SecurityException - if a security manager exists and itscheckPermission method doesn't allow the operation.
throws:
  NullPointerException - if newLocale is null
Parameters:
  newLocale - the new default locale
See Also:   SecurityManager.checkPermission
See Also:   java.util.PropertyPermission




toString
final public String toString()(Code)
Getter for the programmatic name of the entire locale, with the language, country and variant separated by underbars. Language is always lower case, and country is always upper case. If the language is missing, the string will begin with an underbar. If both the language and country fields are missing, this function will return the empty string, even if the variant field is filled in (you can't have a locale with just a variant-- the variant must accompany a valid language or country code). Examples: "en", "de_DE", "_GB", "en_US_WIN", "de__POSIX", "fr__MAC"
See Also:   Locale.getDisplayName



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.