How to change the JVM default locale?

In Java, we can use Locale.setDefault() to change the JVM default locale.

JavaLocaleExample.java

package com.mkyong.locale;

import java.util.Locale;

public class JavaLocaleExample {

    public static void main(String[] args) {

        // get jvm default locale
        Locale defaultLocale = Locale.getDefault();

        System.out.println(defaultLocale);

        // set jvm locale to china
        Locale.setDefault(Locale.CHINA);

        // or like this
        //Locale.setDefault(new Locale("zh", "cn");

        Locale chinaLocale = Locale.getDefault();

        System.out.println(chinaLocale);

    }
}

Output


en_US
zh_CN

Alternatively, in the command line, we can configure the user.country and user.language system property to change the JVM locale.


$ java -Duser.country=cn -Duser.language=zh abc

References

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

avatar