Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Errata OCP Book - Pages 264 and 265 (Sybex)  RSS feed

 
Arif Bin Hewail
Greenhorn
Posts: 3
1
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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.
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37242
519
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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
Sheriff
Posts: 37242
519
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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
Sheriff
Posts: 37242
519
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!