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

mkyong

Founder of Mkyong.com, passionate Java and open-source technologies. If you enjoy my tutorials, consider making a donation to these charities.

1 Comment
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Diego
4 years ago

Thank you very much. This code is exactly what i was looking for. Thanks!