5.4.  Build a resource bundle for each locale


Conceptually each ResourceBundle is a set of related subclasses that share the same base name. The list that follows shows a set of related subclasses. MyApp is the base name. The characters following the base name indicate the language code, country code, and variant of a Locale. MyApp_en_GB, for example, matches the Locale specified by the language code for English (en) and the country code for Great Britain (GB).


To select the appropriate ResourceBundle, invoke the ResourceBundle.getBundle(...) method. The following example selects the MyApp ResourceBundle for the Locale that matches the French language, the country of Canada, and the UNIX platform.

Locale locale = new Locale("fr", "CA", "UNIX");
ResourceBundle introLabels = ResourceBundle.getBundle("MyApp", locale);

Note that getBundle(...) looks for classes based on the default Locale before it selects the base class (MyApp). If getBundle(...) fails to find a match in the preceding list of classes, it throws a MissingResourceException. To avoid throwing this exception, you should always provide a base class with no suffixes.

The abstract class ResourceBundle has two subclasses:

Professional hosting         Free 'Oracle Certified Expert Web Services Developer 6' Guide     Free SCDJWS 5.0 Guide