nerdexam
Oracle

1Z0-819 · Question #148

What is the result of running this code if these three property files are available. employees.properties --------------------- name=Nick age=44 salary=10000 employees_CA.properties…

The correct answer is B. Alice 44 10000. Option B is correct because ResourceBundle.getBundle("employees", new Locale("en", "CA")) searches in a specific hierarchy: employees_en_CA → employees_en → employees (the default). Each bundle delegates missing keys to its parent, so name resolves to "Alice" from…

Localization

Question

What is the result of running this code if these three property files are available.

employees.properties

name=Nick age=44 salary=10000

employees_CA.properties

name=Melissa age=45

employees_en.properties

age=44

employees_en_CA.properties

name=Alice 1 var CA = new Locale("en", "CA"); 2 ResourceBundle b = ResourceBundle.getBundle("employees", CA); 3 System.out.println(b.getString("name")); 4 System.out.println(b.getString("age")); 5 System.out.println(b.getString("salary"));

Options

  • AThrows MissingResourceException
  • BAlice 44 10000
  • CAlice Melissa 10000
  • DNick Alice 10000
  • EThrows some othing else F. Does not compile

How the community answered

(43 responses)
  • A
    2% (1)
  • B
    74% (32)
  • C
    2% (1)
  • D
    16% (7)
  • E
    5% (2)

Explanation

Option B is correct because ResourceBundle.getBundle("employees", new Locale("en", "CA")) searches in a specific hierarchy: employees_en_CAemployees_enemployees (the default). Each bundle delegates missing keys to its parent, so name resolves to "Alice" from employees_en_CA.properties, age falls through to "44" from employees_en.properties, and salary falls all the way to "10000" in the default employees.properties.

Why the distractors fail:

  • C is the most tempting trap: employees_CA.properties is not in the lookup chain for Locale("en", "CA"). That file would only be consulted if the language code were empty (e.g., new Locale("", "CA")), so "Melissa" never appears.
  • D gets the values right but assigns them to wrong keys - a misread of which file contributes which property.
  • A/E are wrong because every key (name, age, salary) is resolvable through the parent chain, so no exception is thrown.
  • F is wrong because Locale(String language, String country) is a valid constructor and all method calls are correct.

Memory tip: Think of the lookup chain as a funnel - language+country → language → default - and remember that a file like employees_CA (country only, no language) is a red herring that only applies when the locale has a blank language code. If you see it in an answer, it's almost certainly a distractor.

Topics

#ResourceBundle#Locale fallback mechanism#Internationalization#Properties file resolution

Community Discussion

No community discussion yet for this question.

Full 1Z0-819 Practice