Locale setDefault() Method in Java with Examples Last Updated : 29 Apr, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report The setDefault(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 host locale. Syntax: public static void setDefault(Locale newLoc) Parameters: The method takes one parameter newLoc of Locale type and this refers to the new default Locale that is to be set. Return Value: The method does not return any value. Exception: The method can throw exceptions like- SecurityException which is thrown if a security manager exists and its checkPermission method doesn't allow the operation. NullPointerException which is thrown if the newLoc is null Below programs illustrate the setDefault() Method of Locale class: Example 1: Java // Java code to illustrate hashCode() method import java.util.*; class Locale_Demo { public static void main(String[] args) { // Creating a new locale Locale first_locale = new Locale("nu", "NO", "NY"); // Displaying first locale System.out.println("First Locale: " + first_locale); // Setting the Locale Locale.setDefault(new Locale("ar", "SA")); Locale new_locale = Locale.getDefault(); // Displaying the hash_code of new locale System.out.println("The Hash Code: " + new_locale); } } Output: First Locale: nu_NO_NY The Hash Code: ar_SA Example 2: Java // Java code to illustrate hashCode() method import java.util.*; class Locale_Demo { public static void main(String[] args) { // Creating a new locale Locale first_locale = new Locale("en", "In"); // Displaying first locale System.out.println("First Locale: " + first_locale); // Setting the Locale Locale.setDefault(new Locale("en", "GB")); Locale new_locale = Locale.getDefault(); // Displaying the hash_code of new locale System.out.println("The Hash Code: " + new_locale); } } Output: First Locale: en_IN The Hash Code: en_GB Reference: https://docs.oracle.com/javase/7/docs/api/java/util/Locale.html#setDefault(java.util.Locale) Comment More infoAdvertise with us Next Article TimeZone setDefault() Method in Java with Examples C chinmoy lenka Follow Improve Article Tags : Misc Java Java - util package Java-Functions Java-Locale +1 More Practice Tags : JavaMisc Similar Reads Scanner locale() method in Java with Examples The locale() method of java.util.Scanner class returns this scanner's locale. Syntax: public Locale locale() Parameters: The function does not accepts any parameter. Return Value: This function returns this scanner's locale Below programs illustrate the above function: Program 1: Java // Java progra 1 min read Locale toString() Method in Java with Examples The toString() method of Locale class in Java is used to return a string representation of this locale. Each element i.e., the language, country or the variant of the locale is separated by underbars Syntax: LOCALE.toString() Parameters: This method does not take any parameters. Return Value: This m 1 min read TimeZone setDefault() Method in Java with Examples The setDefault(TimeZone zone) method of TimeZone class in Java is used to set the TimeZone of the object that is returned by the getDefault() method of the TimeZone class. Syntax: public static void setDefault(TimeZone zone) Parameters: The method takes one parameter zone of TimeZone type which refe 1 min read LocalTime with() Method in Java with Examples In LocalTime class, there are two types of with() method depending upon the parameters passed to it. with(TemporalAdjuster adjuster) with(TemporalAdjuster adjuster) method of the LocalTime class used to adjusted this time using TemporalAdjuster and after adjustment returns the copy of adjusted time. 3 min read LocalDate with() Method in Java with Examples In LocalDate class, there are two types of with() method depending upon the parameters passed to it. with(TemporalAdjuster adjuster) with(TemporalAdjuster adjuster) method of the LocalDate class used to adjusted this date-time using TemporalAdjuster passed as parameter and after adjustment returns t 3 min read Locale.Builder setVariant() method in Java with Examples The setVariant(String) method of java.util.Locale.Builder class in Java is used to set this Locale.Builder to the specified variant. It means that this method will set the current variant of Locale.Builder instance to match the provided variant and return it. If the specified variant is null or empt 2 min read Like