File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Architect Certification (SCEA/OCMJEA) and the fly likes SCEA Question about ResourceBundle: What is your answer? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Architect Certification (SCEA/OCMJEA)
Bookmark "SCEA Question about ResourceBundle: What is your answer?" Watch "SCEA Question about ResourceBundle: What is your answer?" New topic
Author

SCEA Question about ResourceBundle: What is your answer?

Darya Akbari
Ranch Hand

Joined: Aug 21, 2004
Posts: 1855
Hi,

Which of the following statements are true?

  • A: When the matching properties file is not found, the ResourceBundle will load the default properties file.
  • B: When the matching properties file is not found, the ResourceBundle will throw an Exception.
  • C: When the matching properties file is not found, the ResourceBundle will take the next properties file
  • D: When the matching properties file is not found, the ResourceBundle exits the application as it my cause some problem.


  • Regards,
    Darya
    [ August 02, 2006: Message edited by: Darya Akbari ]

    SCJP, SCJD, SCWCD, SCBCD
    Santiago Urrizola
    Ranch Hand

    Joined: Apr 27, 2006
    Posts: 172
    C is the correct answer, for example if you try to load
    come-file_ES_ar.properties
    Resources bundle then try to load these files i order
    come-file_ES_ar.properties
    come-file_ES.properties
    come-file.properties (this is the default file)


    Santiago Urrizola : La Plata - Argentina<br />SCEA (89%-92%)<br /><a href="http://gpitech.wordpress.com/" target="_blank" rel="nofollow">http://gpitech.wordpress.com/</a>
    Ganesan Ponnusamy
    EPractice Labs Support
    Ranch Hand

    Joined: Nov 07, 2005
    Posts: 249
    Hi,

    It will take the default properties file. Just run the following program with only default properties file (LabelsBundle.properties) and see the output.

    So choice A is the correct answer.

    One more request for EPractize Labs users.. please do not post any direct questions from EPractize Labs in forums.

    import java.util.*;

    public class PropertiesDemo {

    static void displayValue(Locale currentLocale, String key) {

    ResourceBundle labels =
    ResourceBundle.getBundle("LabelsBundle",currentLocale);
    String value = labels.getString(key);
    System.out.println(
    "Locale = " + currentLocale.toString() + ", " +
    "key = " + key + ", " +
    "value = " + value);

    } // displayValue


    static void iterateKeys(Locale currentLocale) {

    ResourceBundle labels =
    ResourceBundle.getBundle("LabelsBundle",currentLocale);

    Enumeration bundleKeys = labels.getKeys();

    while (bundleKeys.hasMoreElements()) {
    String key = (String)bundleKeys.nextElement();
    String value = labels.getString(key);
    System.out.println("key = " + key + ", " +
    "value = " + value);
    }

    } // iterateKeys


    static public void main(String[] args) {

    // Locale[] supportedLocales = {
    // Locale.FRENCH,
    // Locale.GERMAN,
    // Locale.ENGLISH
    // };




    iterateKeys( Locale.FRENCH);

    } // main

    } // class



    # This is the LabelsBundle.properties file // default
    s1 = Computer_default
    s2 = Platte_default
    s3 = Monitor_default
    s4 = Tastatur_default

    Thanks & Regards
    Ganesan
    http://www.epractizelabs.com


    Ganesan Ponnusamy Java Certification | Test Generator | OCAJP | OCPJP | OCEJWSD | EJB Certification
    OCEJPAD | SCJD | SCWCD | SCBCD | SCDJWS | OCMJEA | Web Services Certification | SCMAD
    richard baskar
    Greenhorn

    Joined: Apr 20, 2006
    Posts: 4
    A is the correct answer

    regards,
    Richard
    SCJP
    SCEA (Part1)
    elise robinson
    Greenhorn

    Joined: Apr 20, 2006
    Posts: 2
    choice A is the correct answer.

    look at the example from sun http://java.sun.com/docs/books/tutorial/i18n/resbundle/propfile.html

    in that there are 3 properties files
    LabelsBundle.properties (default)
    LabelsBundle_de.properties
    LabelsBundle_fr.properties

    run the program for Locale.FRENCH and Locale.GERMAN by deleting the respective properties files except default.

    thanks
    Robin
    Darya Akbari
    Ranch Hand

    Joined: Aug 21, 2004
    Posts: 1855
    I opt for C for the same reason which Santiago already mentioned.

    Regards,
    Darya
    fitz face
    Greenhorn

    Joined: Apr 20, 2006
    Posts: 2
    darya,can you demonstrate it by a java program? because i feel A is the right choice - fitz
    Darya Akbari
    Ranch Hand

    Joined: Aug 21, 2004
    Posts: 1855
    Hi,

    here is an example on how it works. We have theses files. Put them all in one directory if you want to test it.
  • HelloWorldResources.java
  • MyData.properties
  • MyData_fr.properties
  • MyData_fr_FR.properties


  • And here how they all look like:

    HelloWorldResources.java

    MyData.properties (the default file)


    MyData_fr.properties (the next file)


    MyData_fr_FR.properties


    Compile HelloWorldResources with javac HelloWorldResources.java and run it like:

    java -Duser.language=fr -Duser.region=FR HelloWorldResources

    Remember the output . Remove the MyData_fr_FR.properties from your directory and run the last line again.

    What do you see now ?

    I still stick to Answer C.

    Regards,
    Darya
    [ August 03, 2006: Message edited by: Darya Akbari ]
    Rishi Krishnan
    Greenhorn

    Joined: Jun 08, 2006
    Posts: 28
    C is the correct Answer.

    Refer to Java Internationalization Tutorial.

    http://java.sun.com/docs/books/tutorial/i18n/resbundle/concept.html
    Santiago Urrizola
    Ranch Hand

    Joined: Apr 27, 2006
    Posts: 172
    i, i think here the problem is the meaning of "will take the next properties file" ...
    i assum that next propertie file is the next in the locale name hirarchy convention so ...
    defaul is with no specification an as my example, y try to load a file named:

    example.properties
    for locale "es_AR"
    so i got this files
    example.properties -> this is default used for all other lenguajes (in english)
    example_es.properties -> this is for alla spanish lenguajes
    example_es_AR.properties -> this is for argentina

    so when i try to load resource bundle, systen use locale, to fin the more "nearest" file to this specific locale.
    So if try to load this bundle with argentina locale (es_AR) and i delete all file less than example.propertie, ResourceBundle do this:
    1)first try to load especialized resource bundle for specific country in the locale (es= espa´┐Żol-spanish AR==argentina) file is example_es_AR.properties
    2) if not found, then try to load, resource for the locale lenguaje (es=spanish) so NEXT file is example_es.properties
    3) if not found try to load default example.properties

    so .. i think here the problem is the meanign a wath do you understand by "next file" ...
    Darya Akbari
    Ranch Hand

    Joined: Aug 21, 2004
    Posts: 1855
    Is the example clear ?

    Regards,
    Darya
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: SCEA Question about ResourceBundle: What is your answer?