1Z0-829 · Question #41
Given: Captions.properties file: user = UserName Captions_en.properties file: user = User name (EN) Captions_US.properties file: message = User name (US) Captions_en_US.properties file: message =…
The correct answer is B. The program throws a MissingResourceException. ResourceBundle.getBundle() expects a base name without the .properties extension, but the code passes "Captions.properties" as the base name. Java then searches for files like Captions.properties_en.properties and ultimately Captions.properties.properties - none of which exist…
Question
Options
- AUser name (US)
- BThe program throws a MissingResourceException.
- CUser name (EN - US)
- DUserName
- EUser name (EN)
How the community answered
(58 responses)- A2% (1)
- B74% (43)
- C7% (4)
- D12% (7)
- E5% (3)
Explanation
ResourceBundle.getBundle() expects a base name without the .properties extension, but the code passes "Captions.properties" as the base name. Java then searches for files like Captions.properties_en.properties and ultimately Captions.properties.properties - none of which exist - so it throws a MissingResourceException rather than falling back to the actual Captions.properties file.
Why the distractors fail:
- D (UserName) - looks correct since
Captions.propertieshas that key, but the wrong base name means Java never resolves to it as a fallback - E (User name EN) - would require resolving
Captions_en.properties, which only happens with base name"Captions", not"Captions.properties" - A / C - both US-related bundles (
Captions_US/Captions_en_US) are similarly unreachable for the same reason, and neither even contains the"user"key
Memory tip: Think of the base name as a class name, not a file name - just as you write MyClass, not MyClass.java, you write "Captions", not "Captions.properties". Including the extension is a common trap that breaks bundle resolution entirely.
Topics
Community Discussion
No community discussion yet for this question.