Page 1 of 1

About Question enthuware.ocpjp.v21.2.4019 :

Posted: Mon May 26, 2025 12:31 am
by nkaragulov
msgs.properties is searched for only default Locale?

Re: About Question enthuware.ocpjp.v21.2.4019 :

Posted: Mon May 26, 2025 6:34 am
by admin
No, there is a complete process/algorithm that is used to search properties files for a given key. You can read it in detail either from the javadocs or just go through section 24.3.2 and 24.3.3 of OCP Java 17/21 Fundamentals by Hanumant Deshmukh. Attached is the relevant section:
Localization Looking up a key in resource bundle - OCP 21 Fundamentals - Deshmukh.gif
Localization Looking up a key in resource bundle - OCP 21 Fundamentals - Deshmukh.gif (193.67 KiB) Viewed 3404 times

Re: About Question enthuware.ocpjp.v21.2.4019 :

Posted: Mon May 26, 2025 6:35 am
by admin
And the next page...
Localization Looking up a key in resource bundle - OCP 21 Fundamentals - Deshmukh 2.gif
Localization Looking up a key in resource bundle - OCP 21 Fundamentals - Deshmukh 2.gif (207.95 KiB) Viewed 3404 times

Re: About Question enthuware.ocpjp.v21.2.4019 :

Posted: Tue May 27, 2025 12:34 am
by nkaragulov
Image
I don't get it, why if msgs_fr is not there it is not looking for msgs? I thought it should.

Re: About Question enthuware.ocpjp.v21.2.4019 :

Posted: Tue May 27, 2025 12:56 am
by admin
Did you read the explanation provided with the question thoroughly?
See the lines in bold:
When you look for a resource bundle for Locale.of("fr"), the localization framework will look for msgs_fr.properties file.  However, in the given situation, msgs_fr.properties is not present. Although msgs_fr_FR.properties is present, it will not be used because fr_FR is not a parent of fr. fr is a parent of fr_FR.

Since the localization framework is not able to create a resource bundle for msgs_fr, it will look for a resource bundle for the default locale, which is en_GB. To create a resource bundle for en_GB, it will look for msgs_en_GB.properties, msgs_en.properties, and msgs.properties, in that order. It will not find msgs_en_GB.properties, but the other two are present. Thus, the entry accountinfo={0}''s balance is {1} from msgs_en.properties will be used.
If the above is not clear, please read the relevant sections of the book posted above. If that is not clear, please go through the JavaDoc of getBundle: https://docs.oracle.com/en/java/javase/ ... assLoader)

Re: About Question enthuware.ocpjp.v21.2.4019 :

Posted: Tue May 27, 2025 1:33 am
by nkaragulov
Thank you! Now I get it.