About Question enthuware.ocpjp.v7.2.1201 :

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

Moderator: admin

Post Reply
girish_v
Posts: 7
Joined: Tue Apr 21, 2015 5:26 am
Contact:

About Question enthuware.ocpjp.v7.2.1201 :

Post by girish_v »

Is this question not ambiguous? This is also a valid answer, correct?
"MyResource_fr_CA.java"

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

Re: About Question enthuware.ocpjp.v7.2.1201 :

Post by admin »

Why do you think it is ambiguous?
A .java file is supposed to contain java code, not properties.
If you like our products and services, please help us by posting your review here.

rocky_bgta
Posts: 12
Joined: Thu Dec 11, 2014 12:32 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1201 :

Post by rocky_bgta »

but we can create resource bundle with ListResourceBundle
and save it as .java extension so I think MyResource_fr_CA.java option is also correct.
right?

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

Re: About Question enthuware.ocpjp.v7.2.1201 :

Post by admin »

Assuming that you are talking about something similar to the example given here: http://docs.oracle.com/javase/7/docs/ap ... undle.html
no, it is still a java source file. It is not a resource bundle. It needs to be compiled into a class file.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

thisOtterBeGood
Posts: 14
Joined: Wed Oct 09, 2013 3:13 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1201 :

Post by thisOtterBeGood »

Hi,
I also found the answer rather confusing. If "MyResource_fr_CA.java" would be the correct answer what would be the wording of the question?
which of the following file names represents a valid (?)
Best regards,
Bernhard

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

Re: About Question enthuware.ocpjp.v7.2.1201 :

Post by admin »

Java source code file!
If you like our products and services, please help us by posting your review here.

boyonsea
Posts: 16
Joined: Fri Sep 04, 2015 5:06 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1201 :

Post by boyonsea »

Agree with the OP

why would you write a MyResource_fr_CA.java and not compile it?

I wonder if the OCP exam has such ambiguous questions.

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

Re: About Question enthuware.ocpjp.v7.2.1201 :

Post by admin »

No matter how you try to spin it, MyResource_fr_CA.java is not a resource bundle. You can create a resource bunding using it but the fact is MyResource_fr_CA.java is not a resource bundle. There is no ambiguity here.
If you like our products and services, please help us by posting your review here.

toolforger
Posts: 38
Joined: Fri Nov 13, 2015 4:40 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1201 :

Post by toolforger »

The contention is about the exact definition of "resource bundle".
I'm not sure whether MyResource_fr_CA.class would be considered one. However, the resource bundle is definitely the thing that the Java program accesses at run time, and the running program does not even look at the .java file. So no, the .java file is not a resource bundle, just as the .java file is not a class, it is something that will get compiled into a .class file.

doziransky
Posts: 8
Joined: Wed Mar 16, 2016 10:57 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1201 :

Post by doziransky »

Very confused here.

The following is an excerpt from OCA/OCP Java SE 7 Programmer I & II Study Guide (Exams 1Z0-803 & 1Z0-804):

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Locale locale = new Locale("fr", "CA");
ResourceBundle rb = ResourceBundle.getBundle("RB", locale);

Java will look for the following files in the classpath in this order:

RB_fr_CA.java //exactly what we asked for
RB_fr_CA.properties

//other files if previous weren't found

RB.java //couldn't find anything matching Locale, now trying default bundle
RB.properties

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

So how can this question make the claim that MyResource_fr_CA.java is not a valid resourcebundle file name?

Totally lost here.

Thanks

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

Re: About Question enthuware.ocpjp.v7.2.1201 :

Post by admin »

I think they meant "RB_fr_CA.class //exactly what we asked for". You should confirm with them.

Resource bundles are looked up in the class path. .java files don't reside in the class path. .class files do.

-Paul.
If you like our products and services, please help us by posting your review here.

jagoneye
Posts: 97
Joined: Wed Dec 28, 2016 9:00 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1201 :

Post by jagoneye »

For those who are confused with whether the answer should be
MyResource_fr_CA.java
I also got confused at it first but after reading the documentation it became clearer
To create the ResourceBundle, invoke the getBundlemethod, specifying the base name and Locale:

ResourceBundle labels = ResourceBundle.getBundle("LabelsBundle", currentLocale);
The getBundle method first looks for a class file that matches the base name and the Locale. If it can't find a class file, it then checks for properties files. In the PropertiesDemo program we're backing the ResourceBundle with properties files instead of class files. When the getBundle method locates the correct properties file, it returns a PropertyResourceBundle object containing the key-value pairs from the properties file.


That means if the option said
MyResource_fr_CA.class
then it would be correct since .class file will be considered first and if you are still wondering how a class file can be a resource file, then yes it can be done
by extending your class with ListResourceBundle. Look it up on google or a reference book to know the implementation details. Lucky I studied from Cay Hortsmann's Core Java(which I recommend everyone to refer not only for this exam but also for deep knowledge!). :)

Post Reply

Who is online

Users browsing this forum: No registered users and 231 guests