Online Training Spring Hibernate Training in Delhi R Programming Training Course Big Data and Hadoop Training Java Training

Java Set Default Locale

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.

Ads

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

Advertisements

Ads
Share on Google+Share on Google+

Java Set Default Locale

Posted on: October 14, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

 

Discuss: Java Set Default Locale  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0

Ads

 

Ads