Java Magazine, Nov/Dec 2016
ORACLE COM JAVAMAGAZINE NOVEMBER DECEMBER 2016 69 fix this Which is true Choose one a The code compiles successfully b The code compiles if the throws clause at line n1 is deleted c The code compiles if catch Exception e is added immediately after line n2 d The code compiles if catch MyJobException e is added immediately after line n3 e The code compiles if catch Exception e is added immediately after line n3 Question 1 The correct answer is option B This question is really asking what happens when you try to access a resource bundle for a locale but there is no file defining values for that particular locale When you deploy an internationalized application you try to provide resource files for all the locales in which you expect your software to be used and perhaps you even ofer updates at intervals as you find customers in new locations that you didnt originally support However if the program were to throw an exception when it is used in an unexpected locale that would be pretty harsh so its a fair guess that throwing an exception isnt going to be a good behavior Indeed theres no checked exception when you try to access the file in the first place at line n1 or when you look up the particular value at line n2 On that basis both option D and option E are incorrect If no exception is thrown some text must result The three remaining options amount to saying Java can translate English to French and come up with Aide Java uses the key instead of a value if the value isnt found and Java uses a less perfectly appropriate resource file The actual truth in this situation is the third of these Java uses the best fitting resource file it can find even if that file is the default file Here the only file that exists is the default resource file but Java takes several tries before settling on this A locale is made of several parts Ill simplify the discussion by considering two main parts the language and the region In this case Locale FRANCE refers to the French language as spoken in France which is coded as fr_ FR Given this data the ResourceBundle mechanism tries to find these files in order ConfigData_ fr_ FR properties and ConfigData_ fr properties Notice that the filenames are constructed from three parts the base bundle name ConfigData here then the locale derived part and then the extension properties Strictly speaking several more local variations might be checked with more specific information but the concept is illustrated well enough here If the search has still failed as it will in this example the search is repeated using the systems default locale which might or might not be fr_ FR In this case you dont know whether theres a different default locale and it doesnt matter anyway because only one file exists So the second search fails too After that the system falls back to searching for the default file ConfigData properties The effect of this is that the search finds the bestavailable match If you had a file dedicated to French speakers in France it would be found If thats missing but theres a generalized French language file that would be found Finally as is the case with this question the system falls back to the nonspecific version which in this case contains English By the way this nonspecific version has an oficial name which is base bundle There is a failure mode thats broadly consistent with Answers
You must have JavaScript enabled to view digital editions.