About Question enthuware.ocpjp.ii.v11.2.3311 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
daniko
Posts: 4
Joined: Sun Nov 10, 2019 3:20 pm
Contact:

About Question enthuware.ocpjp.ii.v11.2.3311 :

Post by daniko »

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?

admin
Site Admin
Posts: 8913
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.ii.v11.2.3311 :

Post by admin »

But the language has been set to "en".
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.

daniko
Posts: 4
Joined: Sun Nov 10, 2019 3:20 pm
Contact:

Re: About Question enthuware.ocpjp.ii.v11.2.3311 :

Post by daniko »

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.

admin
Site Admin
Posts: 8913
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.ii.v11.2.3311 :

Post by admin »

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.
If you like our products and services, please help us by posting your review here.

daniko
Posts: 4
Joined: Sun Nov 10, 2019 3:20 pm
Contact:

Re: About Question enthuware.ocpjp.ii.v11.2.3311 :

Post by daniko »

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"));
	}
}
This piece of code loads the bundle mymsgs_IT.properties anyway when it's the only bundle in the classpath and the value of helloMsg is printed...
Running in Eclipse

admin
Site Admin
Posts: 8913
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.ii.v11.2.3311 :

Post by admin »

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.

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests