In Java, we can use Locale.setDefault()
to change the JVM default locale.
JavaLocaleExample.java
package com.favtuts.classic; 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
Download Source Code
$ git clone https://github.com/favtuts/java-core-tutorials-examples
$ cd java-basic/classic