Java Locale setDefault() Example
Locale class setDefault() method example. This example shows you how to use setDefault() method.
Syntax is : public static void setDefault(Locale newLocale)
Method sets the default locale for this instance of the Java Virtual Machine. This does not affect the host locale.The Java Virtual Machine
sets the default locale during startup based on the host environment.
Here is the code.
/**
* @(#) SetDefaultLocale.java
* A class representing use of method setDefault() of Locale class
in java.util Package.
* @Version 24-May-2008
* @author Rose India Team
*/
import java.util.*;
class SetDefaultLocale {
public static void main( String args[] ){
/* Create object of Locale class using contructor
Locale(String language, String country) */
Locale objLocale = new Locale("CH","CHINA");
// getDefault() method call. This is static method.
Locale locale = Locale.getDefault();
System.out.println("current default locale is : " + locale);
// setDefault() method call. This is static method.
Locale.setDefault(objLocale);
System.out.println("##.....Set default locale successfully !");
locale = Locale.getDefault();
System.out.println("Now default locale is : " + locale);
}
} |
Output of the program.
current default locale is : en_US
##.....Set default locale successfully !
Now default locale is : ch_CHINA |
|