Return to site

JAVA CERTIFICATION QUESTION: Localization with ResourceBundle

· java,ocp

Assume we have three files with a property named greeting :

And a code fragment:

It's known that the default locale is en_US.

What is the output of the given code?

  • Compilation fails
  • A MissingResourceException is thrown
  • Nothing
  • Bonjour
  • Hello
  • Default greeting

 

 

#java #certificationquestion #ocp

Answer: Hello

Since the desired locale is fr_CA and the default one is en_US, resources are searched in the following order:

A resource for the fr_CA locale is missing; hence, the program falls back to MyResource_en.properties where it finds a value for the required property.