Chapter THIRTY
Localization


Exam Objectives

Read and set the locale by using the Locale object.
Create and read a Properties file.
Build a resource bundle for each locale and load a resource bundle in an application.

Answers

1. The correct answer is A.
Even though the program creates an invalid Locale object, it doesn't throw any exception. When Java looks up a resource bundle with that locale, it can find any so it resolves to the default bundle (Bundle1.properties).


2. The correct answer is C.
Option A is not a valid constructor of Locale. Option B is wrong, Builder() is not a static method. Option D shows an invalid method (the correct one is forLanguageTag()).


3. The correct answer is C.
The most specific resource bundle will be loaded first, in this case, MyBundle_de. Classes take precedence over properties, so Option C is the correct answer.


4. The correct answer is B.
The string representation of a Locale object is language_country.


5. The correct answer is C.
You can get a value from a resource bundle with two methods:

String getString(String key)
Object getObject(String key)

In the case of property files, you may want to cast to String the returned object of getObject().