Locale Class

Locale Class

A Locale object represents a particular region with respect to country (or) language. It is a final class available in java.util package and implements Serializable and Clonable interfaces.

Construction of Locale Objects

We can construct the Locale Object by using the following Locale class constructor.

 Locale l = new Locale(String Language);
 Locale l = new Locale(String Language, String Country); 

Locale class already defined some standard locale objects in the form of constants.


public static final Locale UK;
public static final Locale ITALY; 
Important methods
 1. public static Locale getDefault():
 Β  Β Returns the default locale configure in JVM.
 2. public static void setDefault(Locale l)
 Β  Β To set our own Locale.
 3. public String getCountry();
 4. public String getDisplayCountry();
 5. public String getLanguages();
 6. public String getDisplayLanguages();
 7. public static String[] getISOCountries()
 Β  Β Returns ISO countries supported by the JVM.
 8. public static String[] getISOLanguages();
 9. public static Locale[] getAvailableLocales(); 
package com.ashok.internationalization;

import java.util.Locale;

public class MyLocale {
   public static void main(String arg[]) {
      Locale loc = Locale.getDefault();
      System.out.println("Country is : " + loc.getCountry() + "Language is -->" + loc.getLanguage());
      System.out.println("Display Country is : " + loc.getDisplayCountry() + "Display Language is -->" + loc.getDisplayLanguage());
      Locale loc2 = new Locale("pa", "IN");
      String str[] = Locale.getISOLanguages();
      System.out.println("ISO Languages are : ");
      for (String str1 : str) {
      String str2[] = Locale.getISOCountries();
      System.out.println("ISO Countries are : ");
      for (String str3 : str2) {
      Locale loc3[] = Locale.getAvailableLocales();
      System.out.println("Available Locales are : ");
      for (Locale loc4 : loc3) {
         System.out.println("Display Country is : " + loc4.getDisplayCountry() + "Display Language is -->" + loc4.getDisplayLanguage());
Locale Class
Scroll to top