Page 1 of 1
About Question enthuware.ocpjp.v7.2.1201 :
Posted: Sun May 31, 2015 12:13 am
by girish_v
Is this question not ambiguous? This is also a valid answer, correct?
"MyResource_fr_CA.java"
Re: About Question enthuware.ocpjp.v7.2.1201 :
Posted: Sun May 31, 2015 1:43 am
by admin
Why do you think it is ambiguous?
A .java file is supposed to contain java code, not properties.
Re: About Question enthuware.ocpjp.v7.2.1201 :
Posted: Sun Jun 14, 2015 1:38 am
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?
Re: About Question enthuware.ocpjp.v7.2.1201 :
Posted: Sun Jun 14, 2015 2:23 am
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.
Re: About Question enthuware.ocpjp.v7.2.1201 :
Posted: Sat Aug 08, 2015 8:58 am
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
Re: About Question enthuware.ocpjp.v7.2.1201 :
Posted: Sat Aug 08, 2015 9:12 am
by admin
Java source code file!
Re: About Question enthuware.ocpjp.v7.2.1201 :
Posted: Sat Sep 05, 2015 3:40 pm
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.
Re: About Question enthuware.ocpjp.v7.2.1201 :
Posted: Sat Sep 05, 2015 9:10 pm
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.
Re: About Question enthuware.ocpjp.v7.2.1201 :
Posted: Wed Jan 27, 2016 12:30 pm
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.
Re: About Question enthuware.ocpjp.v7.2.1201 :
Posted: Fri Apr 01, 2016 10:27 am
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
Re: About Question enthuware.ocpjp.v7.2.1201 :
Posted: Fri Apr 01, 2016 11:17 am
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.
Re: About Question enthuware.ocpjp.v7.2.1201 :
Posted: Tue Jan 03, 2017 1:43 pm
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!).
