Locale Class

Locale Class

In this tutorial, we are going to discuss about Locale Class in java.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.

Locale Class
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
public static Locale getDefault():
    Returns the default locale configure in JVM.
public static void setDefault(Locale l)
    To set our own Locale.
public String getCountry();
public String getDisplayCountry();
public String getLanguages();
public String getDisplayLanguages();
public static String[] getISOCountries()
    Returns ISO countries supported by the JVM.
public static String[] getISOLanguages();
public static Locale[] getAvailableLocales();
package com.ashok.internationalization;

import java.util.Locale;

 * @author ashok.mariyala
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());

That’s all about the Locale class in java. If you have any queries or feedback, please write us email at contact@waytoeasylearn.com. Enjoy learning, Enjoy Java.!!

Locale Class
Scroll to top