nerdexam
Oracle

1Z0-809 · Question #187

Given the content: MessagesBundle.properties file: username = Enter User Name password = Enter Password MessagesBundle_fr_FR.properties file: username = Entrez le nom d'utilisateur password = Entrez…

The correct answer is A. username = Entrez le nom d'utilisateur password = Entrez le mot de passe. Option A is correct because the Locale is built with language "fr" and region "FR", which matches the MessagesBundle_fr_FR.properties file exactly - Java's ResourceBundle.getBundle() selects the most specific locale match available, so the French bundle takes precedence over…

Question

Given the content: MessagesBundle.properties file: username = Enter User Name password = Enter Password MessagesBundle_fr_FR.properties file: username = Entrez le nom d'utilisateur password = Entrez le mot de passe and the code fragment: Locale currentLocale = new Locale.Builder().setRegion("FR").setLanguage("fr").build(); ResourceBundle messages = ResourceBundle.getBundle("MessagesBundle", currentLocale); Enumeration<String> names = messages.getKeys(); while (names.hasMoreElements()) { String key = names.nextElement(); String name = messages.getString(key); System.out.println(key + " = " + name); } What is the result?

Options

  • Ausername = Entrez le nom d'utilisateur password = Entrez le mot de passe
  • Busername = Enter User Name password = Enter Password
  • CA compilation error occurs.
  • DThe program prints nothing.

How the community answered

(23 responses)
  • A
    74% (17)
  • B
    9% (2)
  • C
    13% (3)
  • D
    4% (1)

Explanation

Option A is correct because the Locale is built with language "fr" and region "FR", which matches the MessagesBundle_fr_FR.properties file exactly - Java's ResourceBundle.getBundle() selects the most specific locale match available, so the French bundle takes precedence over the default.

Why the distractors fail:

  • B is wrong because the default MessagesBundle.properties is only used as a fallback when no locale-specific bundle matches - here, fr_FR matches perfectly, so it's never reached.
  • C is wrong because this is valid Java code; Locale.Builder is the modern API (Java 7+) for constructing locales, and all method calls here are correct.
  • D is wrong because the Enumeration returned by getKeys() will contain both "username" and "password" keys, so the loop does execute and produces output.

Memory tip: Think of ResourceBundle as a search from most specific to least specific - it tries language_REGION, then language, then the default file. The first match wins, so a fully matching locale like fr_FR always beats the fallback.

Community Discussion

No community discussion yet for this question.

Full 1Z0-809 Practice