• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Order of files Java goes through to pick a resource bundle

 
Greenhorn
Posts: 27
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All questions here are based on OCP Oracle Certified Professional Java SE 8 Programmer II STUDY GUIDE (EXAM 1Z0-809). ISBN: ISBN-13: 978-1119067900

Is the sequence or the order of files in TABLE 5.7 on Page 264 what Java goes through to find a resource bundle?

The answer to this question is important as the next question depends on it.

At the very bottom of Page 264, we have

**************************************************************************************************************************************

Locale.setDefault(new Locale(“hi”)); // The default Locale is “en_US” and it will become “hi” after expecting this statement.

ResourceBundle rb = ResourceBundle.getBundle(“Zoo”, new Locale(“en”)); // Java will use “Zoo” and “en” to find a match for the bundle.

**************************************************************************************************************************************

If the order or the sequence of files in TABLE 5.7 on Page 264 is indeed what Java goes through to find a resource bundle, then

wouldn’t that make the order or the sequence of the files on the very top of Page 265 wrong if the logic on the order or the sequence presented in TABLE 5.7 is used?

Shouldn’t the order or the sequence of files on Page 265 be as follows?

1) Zoo_en.java // Based on the given “Zoo” and “en”

2) Zoo_en.properties // Based on the given “Zoo” and “en”

3) Zoo_hi.java // Default bundle

4) Zoo_hi.properties // Default bundle

5) Zoo.java

6) Zoo.properties

Thanks a lot for your time.

Schmichael
 
Ranch Hand
Posts: 182
18
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, you are right as per table 5.7 . But it is already specified in the errata here. The order in page 265 must be like 3,4,1,2,5,6.

And in your post 3,4 are Default locale and not Default bundle.
5,6 are the default bundle

1) Zoo_en.java // Based on the given “Zoo” and “en”

2) Zoo_en.properties // Based on the given “Zoo” and “en”

3) Zoo_hi.java // Default locale

4) Zoo_hi.properties // Default locale

5) Zoo.java // Default resource Bundle

6) Zoo.properties // Default resource Bundle
 
Schmichael Chen
Greenhorn
Posts: 27
1
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ramya Subraamanian wrote:Yes, you are right as per table 5.7 . But it is already specified in the errata here. The order in page 265 must be like 3,4,1,2,5,6.

And in your post 3,4 are Default locale and not Default bundle.
5,6 are the default bundle

1) Zoo_en.java // Based on the given “Zoo” and “en”

2) Zoo_en.properties // Based on the given “Zoo” and “en”

3) Zoo_hi.java // Default locale

4) Zoo_hi.properties // Default locale

5) Zoo.java // Default resource Bundle

6) Zoo.properties // Default resource Bundle



Thank you very much. This book is riddled with errors. I've run into a lot more errors but those were minor errors so I was not too bothered by them. This particular error would fundamentally change someone's understanding of the materials.

I respectfully disagree with your premise that "And in your post 3,4 are Default locale and not Default bundle." Both of us were wrong and here is why. I don't mean to be defensive.

I was wrong because it should have been "resource bundle made using default locale." That's what it was.

You were wrong because no default locale comes in with .java or .properties extensions. Only do bundles come in with .java and .properties extensions.

Schmichael
 
Ramya R Subramanian
Ranch Hand
Posts: 182
18
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
IMHO, the book is pretty good. Maybe you feel so...because, you were not aware of the errata. I am also reading the book now. I always refer the errata before starting a chapter, so I wont be confused. It's a good thing that you were able figure this out yourself.

Schmichael Chen wrote:I've run into a lot more errors but those were minor errors so I was not too bothered by them


please feel free to share it with us, so all of us in the forum will know and have them clarified.

Schmichael Chen wrote:You were wrong because no default locale comes in with .java or .properties extensions. Only do bundles come in with .java and .properties extensions.


yeah, here the default locale is just "hi".In 3 & 4 , it means that Zoo_hi.java/Zoo_hi.properties is picked because it makes use of the default locale "hi".

In 5 & 6 the default resource bundle must be the "baseName" that is specified in the getBundle(String baseName, Locale locale). which is Zoo here and so Zoo.java/Zoo.properties is picked.

From the Java docs

Resource bundles belong to families whose members share a common base name, but whose names also have additional components that identify their locales. For example, the base name of a family of resource bundles might be "MyResources". The family should have a default resource bundle which simply has the same name as its family - "MyResources" - and will be used as the bundle of last resort if a specific locale is not supported.


So I just meant that default locale/default resource bundle is used here and not that .java/.properties file are the default ones. I am not sure if my english usage is right but it is something like the "reason" column in the table 5.7. Please do correct me, if my understanding is wrong.
 
reply
    Bookmark Topic Watch Topic
  • New Topic