Home » Java programming language

Java Locale setDefault() Method with Example

Locale Class setDefault() method: Here, we are going to learn about the setDefault() method of Locale Class with its syntax and example.
Submitted by Preeti Jain, on March 08, 2020

Locale Class setDefault() method

  • setDefault() method is available in java.util package.
  • setDefault() method is used to assign the default locale for this Locale instance of the JVM.
  • setDefault() method is a static method, it is accessible with the class name and if we try to access the method with the class object then we will not get an error.
  • setDefault() method may throw an exception at the time of setting locale.
    • SecurityException: This exception may throw when its checkePermission() method does not permit to operate.
    • NullPointerException: This exception may throw when the given parameter is null exists.

Syntax:

    public static void setDefault(Locale lo);

Parameter(s):

  • Locale lo – represents the newly assigned default locale.

Return value:

The return type of the method is void, it returns nothing.

Example:

// Java program to demonstrate the example 
// of void setDefault(Locale lo) method of Locale 

import java.util.*;

public class SetDefaultOfLocale {
    public static void main(String[] args) {
        // Instantiates Locales
        Locale def = Locale.getDefault();
        Locale set_def = new Locale("jap", "JAPAN");

        // Display Locale
        System.out.println("default locale: " + def);

        // By using setDefault() method is
        // to set the default locale
        Locale.setDefault(set_def);
        System.out.println("Locale.setDefault(set_def): " + Locale.getDefault());
    }
}

Output

default locale: en_US
Locale.setDefault(set_def): jap_JAPAN





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.