underscore when linked to the resource bundle name. A resource bundle that has only the
family name is the default bundle. It is used when no language-specific bundles are applicable.
NOTEOTE The language codes are defined by ISO standard 639 and the country codes by ISO
standard 3166.
The methods defined byResourceBundleare summarized in Table 18-17. One important
point:nullkeys are not allowed and several of the methods will throw aNullPointerException
ifnullis passed as the key. Notice the nested classResourceBundle.Control. It was added by
Java SE 6 and is used to control the resource-bundle loading process.
There are two subclasses ofResourceBundle. The first isPropertyResourceBundle, which
manages resources by using property files.PropertyResourceBundleadds no methods of
550 Part II: The Java Library
Method Description
static final void clearCache( ) Deletes all resource bundles from the cache that were
loaded by the default class loader. (Added by Java SE 6.)
static final void
clearCache(ClassLoaderldr)
Deletes all resource bundles from the cache that were
loaded byldr. (Added by Java SE 6.)
boolean containsKey(Stringk) Returnstrueifkis a key within the invoking resource
bundle (or its parent). (Added by Java SE 6.)
static final ResourceBundle
getBundle(StringfamilyName)
Loads the resource bundle with a family name of
familyNameusing the default locale and the default class
loader. ThrowsMissingResourceExceptionif no resource
bundle matching the family name specified byfamilyName
is available.
static final ResourceBundle
getBundle(StringfamilyName,
Localeloc)
Loads the resource bundle with a family name of
familyNameusing the specified locale and the default
class loader. ThrowsMissingResourceExceptionif no
resource bundle matching the family name specified by
familyNameis available.
static ResourceBundle
getBundle(StringfamilyName,
Localeloc,
ClassLoaderldr)
Loads the resource bundle with a family name of
familyNameusing the specified locale and the specified
class loader. ThrowsMissingResourceExceptionif no
resource bundle matching the family name specified by
familyNameis available.
static final ResourceBundle
getBundle(StringfamilyName,
ResourceBundle.Controlcntl)
Loads the resource bundle with a family name of
familyNameusing the default locale and the default class
loader. The loading process is under the control ofcntl.
ThrowsMissingResourceExceptionif no resource bundle
matching the family name specified byfamilyNameis
available. (Added by Java SE 6.)
static final ResourceBundle
getBundle(StringfamilyName,
Localeloc,
ResourceBundle.Controlcntl)
Loads the resource bundle with a family name of
familyNameusing the specified locale and the default
class loader. The loading process is under the control of
cntl. ThrowsMissingResourceExceptionif no resource
bundle matching the family name specified byfamilyName
is available. (Added by Java SE 6.)
TABLE 18-17 The Methods Defined byResourceBundle