← All OCP Flashcard Decks

Date, Time, and Localization Flashcards

7 cards from real OCP practice questions. Tap to flip, then mark Knew It or Still Learning — missed cards come back until you master them.

Read the first 7 Date, Time, and Localization flashcards as text
  1. Which Java class represents a specific geographic, political, or cultural region used for localization?

    Answer: Locale

    Locale represents a specific combination of language, country, and variant used to tailor data formatting and resource lookup for a region.

  2. What is the correct way to obtain a currency-formatted NumberFormat for the US locale?

    Answer: NumberFormat.getCurrencyInstance(Locale.US)

    NumberFormat.getCurrencyInstance(Locale.US) is the standard factory method that returns a formatter configured for currency in the given locale.

  3. What naming convention does Java use for ResourceBundle properties files?

    Answer: BaseName_language_country.properties

    Java expects properties files named as BaseName_language_country.properties (underscore-separated) for locale-specific bundles, e.g., Messages_fr_FR.properties.

  4. In what order does Java search for a ResourceBundle named "Messages" when the locale is Locale("fr", "FR")?

    Answer: Messages_fr_FR.properties → Messages_fr.properties → Messages.properties

    Java searches from most-specific to least-specific: full locale (fr_FR), language only (fr), then the default bundle — stopping at the first match found.

  5. Which method sets the default Locale for only the FORMAT category without changing the DISPLAY category?

    Answer: Locale.setDefault(Locale.Category.FORMAT, newLocale)

    Locale.setDefault(Locale.Category, Locale) accepts a category (FORMAT or DISPLAY) as the first argument, allowing independent defaults for formatting and display purposes.

  6. What does `Locale.getDefault()` return when no default has been explicitly set by the application?

    Answer: The locale derived from the underlying operating system settings by the JVM

    At JVM startup, the default locale is initialized from OS-level language and region settings; it is not hardcoded to English or US unless the OS is configured that way.

  7. Which of the following correctly creates a Locale for Brazilian Portuguese?

    Answer: new Locale("pt", "BR")

    The Locale constructor takes language code first (ISO 639-1: "pt" for Portuguese) and country code second (ISO 3166-1: "BR" for Brazil), giving new Locale("pt", "BR").