Module 29: Java Internationalization (i18n)Beginner18 min read
Locale, ResourceBundle & Currency Formatting
Format currencies, numbers, and dates for global audiences using Locale and NumberFormat.
Key Takeaways & Core Concepts
- `Locale`: Represents a language + region pair (e.g.,
en-IN,en-US,fr-FR). - `ResourceBundle`: Loads locale-specific
.propertiesfiles (messages_en.properties,messages_hi.properties) with automatic fallback to the base bundle. - `NumberFormat` & `DateTimeFormatter`: Format numbers, percentages, currencies, and dates according to regional grouping and symbols.
Locale, ResourceBundle & Currency Formatting
### Internationalization (i18n) & Localization (l10n) Internationalization (i18n) designs software so it can support multiple languages, currencies, and date conventions without code changes; Localization (l10n) supplies the actual translations and regional rules.
- `Locale`: Represents a language + region pair (e.g.,
en-IN,en-US,fr-FR). - `ResourceBundle`: Loads locale-specific
.propertiesfiles (messages_en.properties,messages_hi.properties) with automatic fallback to the base bundle. - `NumberFormat` & `DateTimeFormatter`: Format numbers, percentages, currencies, and dates according to regional grouping and symbols.
Formatting Currency Across Locales
1import java.text.NumberFormat;
2import java.util.Locale;
3
4public class Main {
5 public static void main(String[] args) {
6 double price = 1499.50;
7 NumberFormat inFmt = NumberFormat.getCurrencyInstance(new Locale("en", "IN"));
8 NumberFormat usFmt = NumberFormat.getCurrencyInstance(Locale.US);
9 System.out.println("US: " + usFmt.format(price));
10 System.out.println("IN: " + inFmt.format(price));
11 }
12}
Click code or "Edit Code" to edit
Interactive Code Block•Tab = 4 spaces•Ctrl + Enter = Run
12 lines
Note: `NumberFormat` applies locale-specific grouping separators and currency symbols automatically.
Practice & AssessmentJava Programming Tutorial
Test Your Understanding
Reinforce core concepts with interactive multiple-choice questions, live coding challenges, and top technical interview questions.
Your Current Score
0 / 0 correct(0 attempted)