Results 1 to 6 of 6

Thread: Setting the Default Locale in Java

  1. #1
    Join Date
    Nov 2009
    Posts
    877

    Setting the Default Locale in Java

    Hello, I am working on java programming and currently confused about the setting of the Default locale in java programming language. I have tried to search this on internet, but I am not able to get the satisfactory solution for it. If anyone is having knowledge about the Default Locale in java then please reply about it. Thank you in advance.

  2. #2
    Join Date
    May 2008
    Posts
    2,389

    Re: Setting the Default Locale in Java

    Locales identify a specific language and geographic region. Locale-sensitive objects use java.util.Locale objects to customize how they present and format data to the user. Locales affect user interface language, case mapping, collation (sorting), date and time formats, and number and currency formats. Locales are critical to many culturally and linguistically sensitive data operations.

    A java.util.Locale is a lightweight object that contains only a few important members:
    • A language code
    • An optional country or region code
    • An optional variant code

    Retrieve the default locale using the following method:
    Code:
    public static Locale getDefault()

  3. #3
    Join Date
    Feb 2008
    Posts
    1,852

    Re: Setting the Default Locale in Java

    If you use the Locale class in java then you will able to get the following methods for use:
    • clone()
    • equals(Object obj)
    • getAvailableLocales()
    • getCountry()
    • getDefault()
    • getDisplayCountry(Locale inLocale)
    • getDisplayLanguage()
    • getDisplayLanguage(Locale inLocale)
    • getDisplayName(Locale inLocale)
    • getDisplayVariant(Locale inLocale)
    • getISO3Language()
    • getISOCountries()
    • getISOLanguages()
    • getLanguage()

  4. #4
    Join Date
    Jan 2008
    Posts
    1,521

    Re: Setting the Default Locale in Java

    Hey, you can simply set the default locale in java with the help of following code:
    Code:
    import java.text.*;
    import java.util.Locale;
    public class setDeafultLocale
     {
        public static void main(String[] args)
     {
            Locale L = Locale.getDefault();
            System.out.println("Before setting, Locale is = " + L);
            L = Locale.Japan;
            Locale.setDefault(L);
            System.out.println("After setting, Locale is = " + L);
         }
    }

  5. #5
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Setting the Default Locale in Java

    Hello, If you want to change the default locale in java then you can make use of the code below:
    Code:
    import java.text.DateFormat;
    import java.text.NumberFormat;
    import java.util.Date;
    import java.util.Locale;
    public class SetLocale {
      public static void main(String[] arg) {
        switch (arg.length) {
        case 0:
          Locale.setDefault(Locale.India);
          break;
        case 1:
          throw new IllegalArgumentException();
        case 2:
          Locale.setDefault(new Locale(arg[0], arg[1]));
          break;
        default:
          System.out.println("Usage: SetLocale [language [country]]");
        }
        DateFormat dateformat = DateFormat.getInstance();
        NumberFormat numberformat = NumberFormat.getInstance();
        System.out.println(dateformat.format(new Date()));
        System.out.println(numberformat.format(123.4567));
      }
    }

  6. #6
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Setting the Default Locale in Java

    If you want to set the default locale then java help you with the following two APIs:
    Locale.getDefault():
    If you are using this method then it will simply provide you default locale in all of the locales which you have installed.

    Locale.setDefault():
    If you make use of the method above then it will directly set the locale for the default setting.

Similar Threads

  1. How to restore document and setting to its default junction?
    By Dennis Racket in forum Windows Security
    Replies: 3
    Last Post: 05-03-2012, 01:19 PM
  2. Setting Of Java to The Point At Manual Java
    By winni in forum Software Development
    Replies: 4
    Last Post: 10-01-2011, 10:05 PM
  3. Nokia N78 restarted with default setting
    By MACE in forum Portable Devices
    Replies: 5
    Last Post: 04-01-2010, 06:39 PM
  4. Setting up default Html editor
    By Zaif in forum Software Development
    Replies: 3
    Last Post: 31-03-2009, 10:29 AM
  5. Setting Default IE Window Size
    By Dharmavira in forum Customize Desktop
    Replies: 3
    Last Post: 04-03-2009, 03:28 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,002,375.00145 seconds with 17 queries