Previous | Next | Trail Map | Internationalization | Setting the Locale

Assigning the Default Locale

If you have not assigned a Locale to a locale-sensitive object, it will rely on the Locale returned by the method Locale.getDefault. You can set the default Locale in two ways:

These two techniques for setting the default Locale are shown in the following example:

import java.util.*;

public class DefaultLocale {

   static public void main(String[] args) {

      Properties props = System.getProperties();
      props.put("user.language", "ja");
      props.put("user.region", "JP");
      System.setProperties(props);

      Locale aLocale = Locale.getDefault();
      System.out.println(aLocale.toString());

      aLocale = new Locale("fr", "FR");
      Locale.setDefault(aLocale);
      System.out.println(aLocale.toString());
   }
}
The output of this program is as follows:
ja_JP
fr_FR


Previous | Next | Trail Map | Internationalization | Setting the Locale