
- Java.util - Home
- Java.util - ArrayDeque
- Java.util - ArrayList
- Java.util - Arrays
- Java.util - BitSet
- Java.util - Calendar
- Java.util - Collections
- Java.util - Currency
- Java.util - Date
- Java.util - Dictionary
- Java.util - EnumMap
- Java.util - EnumSet
- Java.util - Formatter
- Java.util - GregorianCalendar
- Java.util - HashMap
- Java.util - HashSet
- Java.util - Hashtable
- Java.util - IdentityHashMap
- Java.util - LinkedHashMap
- Java.util - LinkedHashSet
- Java.util - LinkedList
- Java.util - ListResourceBundle
- Java.util - Locale
- Java.util - Observable
- Java.util - PriorityQueue
- Java.util - Properties
- Java.util - PropertyPermission
- Java.util - PropertyResourceBundle
- Java.util - Random
- Java.util - ResourceBundle
- Java.util - ResourceBundle.Control
- Java.util - Scanner
- Java.util - ServiceLoader
- Java.util - SimpleTimeZone
- Java.util - Stack
- Java.util - StringTokenizer
- Java.util - Timer
- Java.util - TimerTask
- Java.util - TimeZone
- Java.util - TreeMap
- Java.util - TreeSet
- Java.util - UUID
- Java.util - Vector
- Java.util - WeakHashMap
- Java.util - Interfaces
- Java.util - Exceptions
- Java.util - Enumerations
- Java.util Useful Resources
- Java.util - Useful Resources
- Java.util - Discussion
Java Locale setDefault() Method
Description
The Java Locale setDefault(Locale newLocale) method sets the default locale for this instance of the Java Virtual Machine. This does not affect the host locale.
Declaration
Following is the declaration for java.util.Locale.setDefault() method
public static void setDefault(Locale newLocale)
Parameters
newLocale − the new default locale
Return Value
This method returns a hash code value for this object.
Exception
SecurityException − if a security manager exists and its checkPermission method doesn't allow the operation.
NullPointerException − if newLocale is null
Setting Default Locale as CANADA Example
The following example shows the usage of Java Locale setDefault() method. We're getting a default locale, printing it. Then using setDefault() method, we're updating it and then default locale is printed.
package com.tutorialspoint; import java.util.Locale; public class LocaleDemo { public static void main(String[] args) { // print this locale System.out.println("Locale:" + Locale.getDefault()); // Set the default Locale Locale.setDefault(Locale.CANADA_FRENCH); System.out.println("Locale:" + Locale.getDefault()); } }
Output
Let us compile and run the above program, this will produce the following result −
Locale:en_IN Locale:fr_CA
Setting Default Locale as FRANCE Example
The following example shows the usage of Java Locale setDefault() method. We're getting a default locale, printing it. Then using setDefault() method, we're updating it and then default locale is printed.
package com.tutorialspoint; import java.util.Locale; public class LocaleDemo { public static void main(String[] args) { // print this locale System.out.println("Locale:" + Locale.getDefault()); // Set the default Locale Locale.setDefault(Locale.FRANCE); System.out.println("Locale:" + Locale.getDefault()); } }
Output
Let us compile and run the above program, this will produce the following result −
Locale:en_IN Locale:fr_FR
Setting Default Locale as US Example
The following example shows the usage of Java Locale setDefault() method. We're getting a default locale, printing it. Then using setDefault() method, we're updating it and then default locale is printed.
package com.tutorialspoint; import java.util.Locale; public class LocaleDemo { public static void main(String[] args) { // print this locale System.out.println("Locale:" + Locale.getDefault()); // Set the default Locale Locale.setDefault(Locale.US); System.out.println("Locale:" + Locale.getDefault()); } }
Output
Let us compile and run the above program, this will produce the following result −
Locale:en_IN Locale:en_US