About Question enthuware.ocpjp.ii.v11.2.3311 :
Moderator: admin
-
- Posts: 4
- Joined: Sun Nov 10, 2019 3:20 pm
- Contact:
About Question enthuware.ocpjp.ii.v11.2.3311 :
Why is the third option false? The default Locale is set to ITALY, so the fallback method should check for a bundle according to the default locale.
I also ran it with Eclipse and it works. Have i missed something?
I also ran it with Eclipse and it works. Have i missed something?
-
- Site Admin
- Posts: 10062
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.ii.v11.2.3311 :
But the language has been set to "en".
Please post the exact code that you tried and the resource files that you have.
Please post the exact code that you tried and the resource files that you have.
If you like our products and services, please help us by posting your review here.
-
- Posts: 4
- Joined: Sun Nov 10, 2019 3:20 pm
- Contact:
Re: About Question enthuware.ocpjp.ii.v11.2.3311 :
Ahm, Sorry now i got it.
I wrote in my First comment about a fallback. There is no Fallback because the "en" bundle is found but it is empty, so there is no reason to search for the "it".
I tried it in eclipse with only the IT bundle and that's why it worked. My bad.
I wrote in my First comment about a fallback. There is no Fallback because the "en" bundle is found but it is empty, so there is no reason to search for the "it".
I tried it in eclipse with only the IT bundle and that's why it worked. My bad.
-
- Site Admin
- Posts: 10062
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.ii.v11.2.3311 :
In this case, the fallback would be mymsgs_en.properties' parent mymsgs.properties.
mymsgs_it.properties or mymsgs_en_it.properties will not be loaded because the resource bundle is being created for a specific Locale ("en"). If you omit the Locale argument ( i.e. ResourceBundle.getBundle("mymsgs"); ), then files related to the default locale "it" will be used.
mymsgs_it.properties or mymsgs_en_it.properties will not be loaded because the resource bundle is being created for a specific Locale ("en"). If you omit the Locale argument ( i.e. ResourceBundle.getBundle("mymsgs"); ), then files related to the default locale "it" will be used.
If you like our products and services, please help us by posting your review here.
-
- Posts: 4
- Joined: Sun Nov 10, 2019 3:20 pm
- Contact:
Re: About Question enthuware.ocpjp.ii.v11.2.3311 :
Code: Select all
import java.util.Locale;
import java.util.ResourceBundle;
public class LocaleTest {
public static void main(String[] args) {
Locale.setDefault(Locale.ITALY);
Locale loc = new Locale.Builder().setLanguage("en").build();
ResourceBundle rb = ResourceBundle.getBundle("mymsgs", loc);
System.out.println(rb.getString("helloMsg"));
}
}
Running in Eclipse
-
- Site Admin
- Posts: 10062
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.ii.v11.2.3311 :
Ok, I guess I will have to go through this again!
If you like our products and services, please help us by posting your review here.
-
- Posts: 13
- Joined: Sat Mar 08, 2014 1:20 am
- Contact:
Re: About Question enthuware.ocpjp.ii.v11.2.3311 :
Hello,
I do not understand, how can mymsgs_IT.properties be loaded.
Locale ITALY = createConstant("it", "IT");
so the property file for Locale.ITALY should be:
mymsgs_it.properties or
mymsgs_it_IT.properties.
So, I think, at least on Linux, mymsgs_IT.properties will never be loaded.
Is this question/explanation windows-related?
I do not understand, how can mymsgs_IT.properties be loaded.
Locale ITALY = createConstant("it", "IT");
so the property file for Locale.ITALY should be:
mymsgs_it.properties or
mymsgs_it_IT.properties.
So, I think, at least on Linux, mymsgs_IT.properties will never be loaded.
Is this question/explanation windows-related?
-
- Site Admin
- Posts: 10062
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.ii.v11.2.3311 :
Here is the situation:
1. The default Locale is set to Locale.IT That means its language is "it" and country is "IT".
2. A new Locale is being built using Locale loc = new Locale.Builder().setLanguage("en").build(); This means, the language is "en" but the country ( and script and variant) is empty for this Locale.
Now, when you try to load a RB using ResourceBundle.getBundle("mymsgs", loc);, it will look for mymsgs_en.properties only (because country etc. values are empty).
But mymsgs_en.properties is not available, so, getFallbackLocale method is called, which returns the current default locale (here, Locale.IT), and a new search will be made for mymsgs_it_IT.properties and then mymsgs_it.properties
Since mymsgs_it_IT.properties is not available, only mymsgs_it.properties will be loaded (since it is available).
3. Next, the "parent chain" for the resource bundle just loaded (i.e. mymsgs_it_IT.properties) is instantiated. In this case, the parent chain for mymsgs_it_IT.properties will be mymsgs_it and mymsgs.properties (which are not available either as per the problem statement).
Therefore, yes, mymsgs_IT.properties should not be loaded but, since file names are case insensitive on Windows, mymsgs_IT.properties will be loaded on windows.
1. The default Locale is set to Locale.IT That means its language is "it" and country is "IT".
2. A new Locale is being built using Locale loc = new Locale.Builder().setLanguage("en").build(); This means, the language is "en" but the country ( and script and variant) is empty for this Locale.
Now, when you try to load a RB using ResourceBundle.getBundle("mymsgs", loc);, it will look for mymsgs_en.properties only (because country etc. values are empty).
But mymsgs_en.properties is not available, so, getFallbackLocale method is called, which returns the current default locale (here, Locale.IT), and a new search will be made for mymsgs_it_IT.properties and then mymsgs_it.properties
Since mymsgs_it_IT.properties is not available, only mymsgs_it.properties will be loaded (since it is available).
3. Next, the "parent chain" for the resource bundle just loaded (i.e. mymsgs_it_IT.properties) is instantiated. In this case, the parent chain for mymsgs_it_IT.properties will be mymsgs_it and mymsgs.properties (which are not available either as per the problem statement).
Therefore, yes, mymsgs_IT.properties should not be loaded but, since file names are case insensitive on Windows, mymsgs_IT.properties will be loaded on windows.
If you like our products and services, please help us by posting your review here.
-
- Posts: 13
- Joined: Sat Mar 08, 2014 1:20 am
- Contact:
Re: About Question enthuware.ocpjp.ii.v11.2.3311 :
Hello,
Thank you.
Thank you.
Who is online
Users browsing this forum: No registered users and 118 guests