About Question enthuware.ocpjp.v21.2.4019 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
nkaragulov
Posts: 17
Joined: Mon Sep 16, 2024 1:49 am
Contact:

About Question enthuware.ocpjp.v21.2.4019 :

Post by nkaragulov »

msgs.properties is searched for only default Locale?

admin
Site Admin
Posts: 10382
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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 3035 times

admin
Site Admin
Posts: 10382
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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 3035 times

nkaragulov
Posts: 17
Joined: Mon Sep 16, 2024 1:49 am
Contact:

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

Post 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.

admin
Site Admin
Posts: 10382
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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)

nkaragulov
Posts: 17
Joined: Mon Sep 16, 2024 1:49 am
Contact:

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

Post by nkaragulov »

Thank you! Now I get it.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 85 guests