The setDefault(Locale.Category cate, Locale newLoc) method of Locale class in Java is used to set the default locale for this instance of the JVM or the Java Virtual machine and this in no way affects the locale host.
public static void setDefault(Locale.Category cate, Locale newLocale)
Parameters: The method takes two parameters:
- cate: This is of Locale.Category type and specifies the category to which the default locale is to be set.
- newLoc: This is also of locale type and refers to the new default locale.
Return Value: The method does not return any value.
Exception: The method can throw exceptions like-
- SecurityException: This is thrown if a security manager exists and its checkPermission method doesn’t allow the operation.
- NullPointerException: This is thrown if the newLoc is null.
Below programs illustrate the setDefault() Method of Locale class:
First Locale: nu_NO_NY The Hash Code: en_US
First Locale: en_IN The Hash Code: en_US
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.