Home

This Chapter
-Chapter 7: Internationalization
-New Supported Locales
-Locale Sensitive Services SPI
-Resource Bundle Enhancement
-ResourceBundle.Control
-Summary

Table of Contents
-Introduction
-Chapter 1: Core Libraries
-Chapter 2: Dynamic Compilation
-Chapter 3: Scripting
-Chapter 4: Networking
-Chapter 5: Swing Updates
-Chapter 6: Abstract Window Toolkit
-Chapter 7: Internationalization
-Chapter 8: Java Database Connectivity 4.0
-Chapter 9: XML Digital Signature API
-Chapter 10: Streaming API for XML
-Chapter 11: Java Architecture for XML Binding
-Chapter 12: Web Services
-Chapter 13: JavaBeans Activation Framework
-Chapter 14: User-Defined MXBeans
-Chapter 15: Concurrency Updates
-Appendix A: Enums
-Appendix B: Generics
-Appendix C: Annotations

Previous
Next

 

New Supported Locales

Java 6 ships with ten new locales. They are listed in Table 7.1.

As an example, consider the code in Listing 7.1 that uses the new locale Japanese calendar.

Language Country Locale Identifier
Chinese (Simplified) Singapore zh_SG
English Malta en_MT
English Philippines en_PH
English Singapore en_SG
Greek Cyprus el_CY
Indonesian Indonesia in_ID
Japanese (Japanese calendar) Japan ja_JP_JP
Malay Malaysia ms_MY
Maltese Malta mt_MT
Spanish US es_US

Table 7.1: New locales in Java 6

Listing 7.1: Japanese calendar testing

import java.text.DateFormat;
import java.util.Calendar;
import java.util.Locale;
import javax.swing.JOptionPane;

public class JapaneseCalendar {

    public static void main(String[] args) {

        // Create Japanese locale
        Locale japanese = new Locale("ja", "JP", "JP");

        Calendar cal = Calendar.getInstance(japanese);
        System.out.println(cal);

        // Format time
        DateFormat df = DateFormat.getDateTimeInstance(
                DateFormat.FULL, DateFormat.FULL, japanese);
        String str = df.format(cal.getTime());

        // Display the string in JOptionPane
        JOptionPane.showMessageDialog(null, str);
    }
}

If you run the JapaneseCalendar class in Listing 7.1, you’ll see a JOptionPane similar to that in Figure 7.1. The JOptionPane contains a date and time in the new Japanese locale.

Figure 7.1: Using the new Japanese locale

Previous
Next