Home Java Javadate Java Set Default Locale
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

Java Set Default Locale

Advertisement
Locale can be set also in our java programs by using the method setDefault() of Locale class. In this example we have set the default locale value of our Locale with the Locale.ITALY.

Java Set Default Locale

     

Setting Default Locale Example in Java

Locale can be set also in our java programs by using the method setDefault() of Locale class. In this example we have set the default locale value of our Locale with the Locale.ITALY.

In our example of setting default locale value we can get the value of default locale by using getDefault() method. Here it is English and now we have to change it with our Locale with the use of setDefault() method of Locale class. 

Locale locale = Locale.getDefault(); creates Locale class object by getting the default locale.

locale = Locale.ITALY;
Locale.setDefault(locale);

Above lines of code sets locale to ITALY and then sets the default locale value to this locale. Here is the full example code of SettingLocale.java as follows:

SettingLocale.java

import java.text.*;
import java.util.Locale;

public class SettingLocale {
  public static void main(String[] args) {
  // Getting default locale
  Locale locale = Locale.getDefault();
  System.out.println("Before setting, Locale is = " + locale);
  // Setting default locale  
  locale = Locale.ITALY;
  Locale.setDefault(locale);
  System.out.println("After setting, Locale is = " + locale);
 }
}

Output:

C:\DateExample>javac SettingLocale.java

C:\DateExample>java SettingLocale
Before setting, Locale is = en_US
After setting, Locale is = it_IT

Download Source Code

Advertisement

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: October 14, 2008

Ask Questions?    Discuss: Java Set Default Locale  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com