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

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 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", "JA");
      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_JA
fr_FR
Don't rely on the default Locale unless you set it ahead of time with one of the two methods shown above. If you don't, you may find that the the Locale returned by getDefault may not be the same on all Java platforms.


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