OCP Flashcards – 12. Localization

OCP Exam Objective 12 – Localization

Flashcard OCP.12.Localization.001

What is localization?

Click here to view answer
It’s the process of adapting an internationalized application to a specific region or language.

 

Flashcard OCP.12.Localization.002

What’s an internationalized application?

Click here to view answer
An application that can adapt to various languages and regions without recompilation.

 

Flashcard OCP.12.Localization.003

How can you adapt your application to different languages and regions?

Click here to view answer
By adding localization data to the executable file.

 

Flashcard OCP.12.Localization.004

What do a locale and the java.util.Locale class represent?

Click here to view answer
A locale represents a language, culture, or country; the java.util.Locale class provides an abstraction for this concept by identifying specific language and region.

 

Flashcard OCP.12.Localization.005

What does a locale contain?

Click here to view answer
Each locale can have three entries: the language, country, and variant. You can use standard codes available for language and country to form locale tags. Variants are not on the OCP exam.

 

Flashcard OCP.12.Localization.006

How would you set and change the default locale in the JVM?

Click here to view answer
The Locale#getDefault() method returns the default locale. It is also possible to change it to another locale by using the setDefault() method.

 

Flashcard OCP.12.Localization.007

How would you create a Locale object?

Click here to view answer
Within the OCP Exam context:

  • By using the constructor of the Locale class; or
  • By building a Locale object by instantiating Locale.Builder; or
  • By using the predefined static final constants for locales in the Locale class.

 

Flashcard OCP.12.Localization.008

What is a resource bundle?

Click here to view answer
A resource bundle is a set of classes or property files that help define a set of keys and map those keys to locale-specific values.

 

Flashcard OCP.12.Localization.009

What is a properties file used in localization?

Click here to view answer
A text file that contains name/value pairs for a specified resource bundle.

 

Flashcard OCP.12.Localization.010

What is the syntax for properties in a properties file?

Click here to view answer
=, space and : can be used as delimiters; spaces before or after the delimiter character are ignored; at the end of the line not ignored.

 

Flashcard OCP.12.Localization.011

What are the key and value for this pair:

greetings := “Salut, camarades!”

Click here to view answer
The key is greetings and the value is = “Salut, camarades!”

Reason (as per javadoc for java.util.Properties#load()):

The key contains all of the characters in the line starting with the first non-white space character and up to, but not including, the first unescaped ‘=’, ‘:’, or white space character other than a line terminator. If the first non-white space character after the key is ‘=’ or ‘:’, then it is ignored and any white space characters after it are also skipped.

 

Flashcard OCP.12.Localization.012

What are the requirements for naming a properties file?

Click here to view answer
It must match the resource bundle, including the language/region identifiers, and ends with the .properties extension.

 

Flashcard OCP.12.Localization.013

What would be the properties filename for the resource bundle MyData for the French language?

MyData_fr.properties[/expand]

 

Flashcard OCP.12.Localization.014

What would be the properties filename for the resource bundle MyData for the French Canadian locale?

Click here to view answer
MyData_fr_CA.properties

 

Flashcard OCP.12.Localization.015

What is the difference between the Properties and ResourceBundle datatypes in respect to localization?

Click here to view answer
While both types represent mapped key/value String pairs, ResourceBundle has been designed specifically to be used in localization while Properties is just a key/value list that can be saved to or loaded from a stream.

 

Flashcard OCP.12.Localization.016

How would you go about getting a property when you suspect that its key might not be found but the null value is unacceptable?

Click here to view answer
This is exactly what the java.util.Properties#getProperty(String key, String defaultValue) method is for: it returns the specified defaultValue if the key is not found in this property list, the default property list, and its defaults, recursively.

Leave Comment

Your email address will not be published.