Menu
Topics Index
...
`

LocaleDemo - Java Example Program


LocaleDemo
import java.util.Locale;

class LocaleDemo
{
    public static void main(String[] args)
    {
        Locale l = Locale.getDefault(); // LINE A
        System.out.println(l);
        System.out.println(l.getDisplayCountry()); // LINE B
        System.out.println(l.getCountry()); // LINE C
        System.out.println(l.getDisplayLanguage()); // LINE D
        System.out.println(l.getLanguage()); // LINE E
    }
}
OUTPUT

en_US
United States
US
English
en

DESCRIPTION

In the above program at LINE A we are getting the current value of the default locale of the Java Virtual Machine. At LINE B , LINE Cwe are printing the appropriate country name and country code. At LINE D, LINE E we are printing country language and language code.

THINGS TO TRY
  • Set the default locale as CANADA
  • Display the country name and language

© meritcampus 2019

All Rights Reserved.

Open In App