nerdexam
Oracle

1Z0-819 · Question #184

Given config: MessageBundle.properties: username = Username password = Password and MessageBundle_fr_FR.properties: username = Utilisateur password = le passe and MessageBundle_ru.properties…

The correct answer is D. User = Utilisateur Pass = le passe E. User username. Option D is partially correct in that Locale.FRANCE resolves to fr_FR, so ResourceBundle.getBundle("MessageBundle", Locale.FRANCE) finds and loads MessageBundle_fr_FR.properties, returning "Utilisateur" for username. However, the stated answer key appears to contain an error…

Question

Given config: MessageBundle.properties: username = Username password = Password and MessageBundle_fr_FR.properties: username = Utilisateur password = le passe and MessageBundle_ru.properties: username = пользователь password = Пароль and the code fragment: public class Test { public static void main(String[] args) { ResourceBundle msg = ResourceBundle.getBundle("MessageBundle", Locale.FRANCE); ResourceBundle msg_ru = ResourceBundle.getBundle("MessageBundle", new Locale("ru")); System.out.println("User = " + msg.getString("username") + " Pass = " + msg_ru.getString("password")); } } What is the result?

Options

  • AUser = пользователь Pass = Пароль
  • BThe compilation fails.
  • CMissingResourceException is thrown at runtime.
  • DUser = Utilisateur Pass = le passe
  • EUser username

How the community answered

(39 responses)
  • A
    3% (1)
  • B
    15% (6)
  • C
    5% (2)
  • D
    77% (30)

Explanation

Option D is partially correct in that Locale.FRANCE resolves to fr_FR, so ResourceBundle.getBundle("MessageBundle", Locale.FRANCE) finds and loads MessageBundle_fr_FR.properties, returning "Utilisateur" for username. However, the stated answer key appears to contain an error: new Locale("ru") resolves to MessageBundle_ru.properties, so msg_ru.getString("password") returns "Пароль" - not "le passe" as D claims. The actual output would be User = Utilisateur Pass = Пароль, which isn't cleanly represented by any single option as written (option E appears to be a corrupted/truncated distractor in this dump).

Why the other options are wrong:

  • A is wrong on the username side - "пользователь" is the Russian username, but msg uses the French (fr_FR) bundle, not the Russian one.
  • B is wrong - the code compiles fine; ResourceBundle, Locale, and getString are all valid Java SE API calls.
  • C is wrong - both bundle files exist and both keys (username, password) are present in them, so no MissingResourceException is thrown.

Memory tip: Think of ResourceBundle.getBundle() as a "most specific match wins" lookup: it tries lang_COUNTRYlang → default bundle in order, stopping at the first file found. Locale.FRANCE = fr_FR hits the _fr_FR file directly; new Locale("ru") (language-only) hits _ru directly - neither falls back to the default.

Community Discussion

No community discussion yet for this question.

Full 1Z0-819 Practice