nerdexam
Oracle

1Z0-819 · Question #98

Which two statements set the default locale used for formatting numbers, currency, and percentages? (Choose two.)

The correct answer is B. Locale.setDefault(new Locale.Builder().setLanguage("en").build()); C. Locale.setDefault(new Locale.Builder().setLanguage("en").setRegion("CA").build()). Options B and C are correct because Locale.setDefault() requires a Locale object as its argument, and both use Locale.Builder - the modern, standards-compliant way to construct one - producing valid Locale instances that Java's formatting APIs (numbers, currency, percentages)…

Localization

Question

Which two statements set the default locale used for formatting numbers, currency, and percentages? (Choose two.)

Options

  • ALocale.setDefault(Locale.Category.FORMAT, "zh-CN");
  • BLocale.setDefault(new Locale.Builder().setLanguage("en").build());
  • CLocale.setDefault(new Locale.Builder().setLanguage("en").setRegion("CA").build());
  • DLocale.setDefault("en_US");

How the community answered

(25 responses)
  • A
    12% (3)
  • B
    84% (21)
  • D
    4% (1)

Explanation

Options B and C are correct because Locale.setDefault() requires a Locale object as its argument, and both use Locale.Builder - the modern, standards-compliant way to construct one - producing valid Locale instances that Java's formatting APIs (numbers, currency, percentages) will use globally.

Why the distractors fail:

  • A is wrong on two levels: the two-argument overload Locale.setDefault(Category, Locale) takes a Locale as the second argument, not a String like "zh-CN". Passing a raw string causes a compile error.
  • D is wrong for the same core reason: there is no overload of Locale.setDefault() that accepts a String. Java's API requires an actual Locale object, not a locale tag string.

Memory tip: Think of Locale.setDefault() as a typed setter - it only accepts a Locale, never a String. If you see a string passed directly (like "zh-CN" or "en_US"), it's always wrong. The safe builder pattern is new Locale.Builder().setLanguage(...).setRegion(...).build().

Topics

#Locale#Localization#Locale.Builder#Text Formatting

Community Discussion

No community discussion yet for this question.

Full 1Z0-819 Practice