This week's book giveaway is in the NodeJS forum.
We're giving away four copies of Serverless Applications with Node.js and have Slobodan Stojanovic & Aleksandar Simovic on-line!
See this thread for details.
Win a copy of Serverless Applications with Node.js this week in the NodeJS forum!
  • 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:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

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
Posts: 39208
726
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
Posts: 39208
726
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!
 
Marshal
Posts: 63826
209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I merged your stuff with the following thread. I hope that is okay by you.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What about the table Table 5.7 it gives something. What about the order that given on page 264 of OCP book by same author.
table-5.7.png
[Thumbnail for table-5.7.png]
 
Campbell Ritchie
Marshal
Posts: 63826
209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please don't ask a new question on an old th‍read; that merits a new  th‍read.

Remember: XYZ_fr_FR is more specific than XYZ_fr. And don't properties files have to have .properties as their extension?
 
Dhananjaykumar Kushwaha
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, it is the same question. I had still had doubts. Why the program use Dolphins.properties rather than Dolphins_en.properties as it is more specific according to the table that i had given??
 
Campbell Ritchie
Marshal
Posts: 63826
209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All right, I can put the two discussions back together.
 
Campbell Ritchie
Marshal
Posts: 63826
209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you find the dolphin_fr.properties file and the only path thereafter is, as Jeanne said last year, is to remove the _fr to get plain simple dolphin.properties. You cannot add _en at that stage. Remember the Locale requested was French.
 
Dhananjaykumar Kushwaha
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does that means that the hierarchy that book is given is wrong ie:
Zoo_fr_FR.java -> Zoo_fr_FR.properties -> Zoo_fr.java ->Zoo_fr.properties -> Zoo_en_US.java -> Zoo_en_US.properties -> Zoo_en.java ->zoo_en.properties -> Zoo.java ->Zoo.properties
 
Campbell Ritchie
Marshal
Posts: 63826
209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Didn't you see what Jeanne said a year ago about following paths through the many properties bundle files?
 
Dhananjaykumar Kushwaha
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For name we will use Dolphins_fr.properties but for age why we are using Dolphins.properties rather than Dolphins_fr.properties as it is more specific as Dolphins_en.properties is the default locale ie en US. Please give me some links, where i can study more about it.
 
Campbell Ritchie
Marshal
Posts: 63826
209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The dolphins_fr.properties file doesn't have an age property. So it is necessary to continue to the less specific file.
 
Dhananjaykumar Kushwaha
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to say that Dolphins_en.properties has age why not it use from it, as it is more specific than Dolphins.properties
 
Campbell Ritchie
Marshal
Posts: 63826
209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dhananjaykumar Kushwaha wrote:. . . Dolphins_en.properties . . . why not it use from it . . .

Because you specified French with the argument "fr" (lines 5 and 7), so you cannot use a file with “_en” in is name.
 
If I had asked people what they wanted, they would have said faster horses - Ford. Tiny ad:
global solutions you can do at home or in your backyard
https://www.kickstarter.com/projects/paulwheaton/better-world-boo
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!