• 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

Errata OCP Book - Pages 264 and 265 (Sybex)

 
Greenhorn
Posts: 3
1
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
in pages 264 and 265 of the OCP Java book, there is an error. In table 5.7 default locale and default language should come after the root resource bundle java class or file.

Asking for a resource bundle for French in France with default locale US English, will make java look for french resources first till the top of the hierarchy of resources (the base resource) and then switch to the default locale or language.

It should look like this:

1.
2.
3.
4.
5. Zoo.java
6. Zoo.properties
7. Zoo_en_US.java
8. Zoo_en_US.properties
9. Zoo_en.java
10. Zoo_en.properties
11. If still not found, throw MissingResourceException

Number 5 and 6 are the base for all resources, so Java will look for them before searching for the default locale or default language.

Based on this page 265 should be as follows:

1. Zoo_en.java
2. Zoo_en.properties
3. Zoo.java
4. Zoo.properties
5. Zoo_hi.java
6. Zoo_hi.properties

This is based on the code on page 264, where you ask for English resource.
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Arif,
I'm seeing the behavior described in the book not the behavior you described.

I created three files:
Zoo_en_US.properties


Zoo.properties


Then I ran this program:


The output was English which shows it used the default locale before Zoo.properties.
 
Arif Bin Hewail
Greenhorn
Posts: 3
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jeanne,

In your case, you don't have a French resource file, so there is no hierarchy established from French resource and the root resource file (Zoo.properties). Java went to the default resource file (Zoo_en_US.properties) immediately.

However, to understand my point, just add a blank French resource file (Zoo_fr_FR.properties) and run your code. You should get the value none for a.


 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Arif,
Oh!. Now I get your point! That table assumes that the file is either not present or has the property value in it. Oracle doesn't put blank property files on the exam.

I gave a cow for an interesting and well thought out example.
 
Arif Bin Hewail
Greenhorn
Posts: 3
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jeanne,

Picking a resource is based on searching for a key. Suggesting to use a blank resource file was just to illustrate the point. However, if a locale resource file is present, but the key was not found inside it, where does Java go to search for the key?
Does it go to the root resource files or default resource files? It goes to the root resource files as shown by the example.

Therefore, I believe the correct order for table 5.7 is as outlined in my first post. The same thing applies to the list in page 265.

If a locale specific files are missing, then there is no need for any ordering as the search immediately goes to the default resource files and then the root resources.
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Arif,
I understand. I'm saying that the table is a simplifier version of the world where only property files with the property exist (or the file doesn't exist at all.) This is important for understanding the initial order.
reply
    Bookmark Topic Watch Topic
  • New Topic