• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SCEA Question about ResourceBundle: What is your answer?

 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
     
    Santiago Urrizola
    Ranch Hand
    Posts: 172
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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)
     
    Ganesan Ponnusamy
    MyExamCloud Support
    Ranch Hand
    Posts: 264
    5
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
     
    richard baskar
    Greenhorn
    Posts: 4
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    A is the correct answer

    regards,
    Richard
    SCJP
    SCEA (Part1)
     
    elise robinson
    Greenhorn
    Posts: 2
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 1855
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I opt for C for the same reason which Santiago already mentioned.

    Regards,
    Darya
     
    fitz face
    Greenhorn
    Posts: 2
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    darya,can you demonstrate it by a java program? because i feel A is the right choice - fitz
     
    Darya Akbari
    Ranch Hand
    Posts: 1855
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 28
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 172
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 1855
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Is the example clear ?

    Regards,
    Darya
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic