This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Journey To Enterprise Agility and have Daryl Kulak & Hong Li on-line!
See this thread for details.
Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

OCP Chapter 5 Q#5 Jeanne Boyarsky  RSS feed

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

  Is the answer in OCP Chapter 5 Q#5 in Jeanne Boyarsky's book should be letter E?

This is the question.

5. Suppose that we have the following property files and code. Which bundles are used on lines 8 and 9 respectively?
Dolphins.properties name=The Dolphin age=0
Dolphins_en.properties name=Dolly
age=4
Dolphins_fr.properties name=Dolly
5: Locale fr = new Locale("fr");
6: Locale.setDefault(new Locale("en", "US"));
7: ResourceBundle b = ResourceBundle.getBundle("Dolphins", fr);
8: b.getString("name");
9: b.getString("age");
A. Dolphins.properties and Dolphins.properties
B. Dolphins.properties and Dolphins_en.properties
C. Dolphins_en.properties and Dolphins_en.properties
D. Dolphins_fr.properties and Dolphins.properties
E. Dolphins_fr.properties and Dolphins_en.properties
F. The code does not compile.

As I understand, it should if it didn't find the java/properties file in the given locale it will next search for the default locale.
TIA
 
Rhea Camille
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ooops.. sorry for poor code format, here's the edited one.

Dolphins.properties
     name=The Dolphin
     age=0
Dolphins_en.properties
    name=Dolly
    age=4
Dolphins_fr.properties
   name=Dolly


5: Locale fr = new Locale("fr");
6: Locale.setDefault(new Locale("en", "US"));
7: ResourceBundle b = ResourceBundle.getBundle("Dolphins", fr);
8: b.getString("name");
9: b.getString("age");
A. Dolphins.properties and Dolphins.properties
B. Dolphins.properties and Dolphins_en.properties
C. Dolphins_en.properties and Dolphins_en.properties
D. Dolphins_fr.properties and Dolphins.properties
E. Dolphins_fr.properties and Dolphins_en.properties
F. The code does not compile.
 
author & internet detective
Marshal
Posts: 38502
653
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, D is correct (as in the book.)

There's two "navigation ways" for resource bundle lookups. The first is finding the closest matching bundle. That's Dolphins_fr.properties. You understand that since you asked about Option E.

Once Java finds a matching bundle, it can only navigate up the hierarchy. So it can use a more general bundle (Dolphins.properties) but not jump to a different one.

This means if  Dolphins_fr.properties did not exist, using  Dolphins_en.properties would be fine. Becauase it would use the default locale instead of the provided one. But since the provided locale is found, the default one isn't used at all.
 
Rhea Camille
Greenhorn
Posts: 7
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jeanne,

Thank you for clearing that up, my memory messed, I also re-read that chapter and yes, it will find the requested locale first, then the language with no country then the last one will be the default locale.

Cheers!

 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 38502
653
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glad it is clear now. Far better to get it clarified now than get it wrong on the exam!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!