The Java Program: Main.java
1 import java.util.Locale;
2 import java.util.MissingResourceException;
3
4 class Main {
5
6 static void print (String name, Locale locale) {
7 try {
8 System.out.format ("%-15s:", name);
9 System.out.print (" " + locale.getDisplayLanguage());
10 System.out.print (" " + locale.getLanguage());
11 System.out.print (" " + locale.getISO3Language());
12 System.out.print (" : " + locale.getDisplayCountry());
13 System.out.print (" " + locale.getCountry());
14 System.out.print (" " + locale.getISO3Country());
15 System.out.print (" : " + locale.getDisplayVariant());
16 System.out.print (" " + locale.getVariant());
17 System.out.print (" : " + locale.getDisplayName());
18 } catch (MissingResourceException e) {
19 System.out.print (" #*!? ");
20 } finally {
21 System.out.print (" : " + locale.toString());
22 System.out.println ();
23 }
24 }
25
26 public static void main (String[] args) {
27
28 System.out.println ("\nLocale's notion of default:");
29 print("default", Locale.getDefault());
30
31 System.out.println ("\nPredefined locales:");
32 print ("CANADA", Locale.CANADA);
33 print ("CANADA_FRENCH", Locale.CANADA_FRENCH);
34 print ("CHINA", Locale.CHINA);
35 print ("CHINESE", Locale.CHINESE);
36 print ("ENGLISH", Locale.ENGLISH);
37 print ("FRANCE", Locale.FRANCE);
38 print ("FRENCH", Locale.FRENCH);
39 print ("GERMAN", Locale.GERMAN);
40 print ("GERMANY", Locale.GERMANY);
41 print ("ITALIAN", Locale.ITALIAN);
42 print ("ITALY", Locale.ITALY);
43 print ("JAPAN", Locale.JAPAN);
44 print ("JAPANESE", Locale.JAPANESE);
45 print ("KOREA", Locale.KOREA);
46 print ("KOREAN", Locale.KOREAN);
47 print ("RPC", Locale.PRC);
48 print ("SIMPLIFIED_CHINESE", Locale.SIMPLIFIED_CHINESE);
49 print ("TAIWAN", Locale.TAIWAN);
50 print ("TRADITIONAL_CHINESE", Locale.TRADITIONAL_CHINESE);
51 print ("UK", Locale.UK);
52 print ("US", Locale.US);
53
54 System.out.println ("\nInstalled locales:");
55 final Locale[] locales = Locale.getAvailableLocales();
56 for (int i=0; i<locales.length; i++) {
57 print (locales[i].toString(), locales[i]);
58 }
59 }
60 }