How To Set Default Locale In Java

Every system has its own default locale set in the native library. It is based on the current location or country of that operating system is accessed. Java has API to access the locales and display the text on appropriate languages. In some cases, the default locale may not be correct or it needs change for your application to work correctly. It is easy to change the default locale in Java. Look at the below program to understand how to change the default locale.


import java.util.Locale;

public class DefaultLocaleExample {
	public static void main(String[] args) {
		System.out.println("Default locale:" + Locale.getDefault().toString());
		System.out.println("Default Language:" + Locale.getDefault().getDisplayLanguage());

		//Setting the default locale to India and Hindi Language
		Locale indiaLocale = new Locale("hi", "IN");

		System.out.println("New default locale:" + Locale.getDefault().toString());
		System.out.println("New Default locale Language:" + Locale.getDefault().getDisplayLanguage());


Default locale:en_IN
Default Language:English
New default locale:hi_IN
New Default locale Language:हिंदी

Leave a Reply

Your email address will not be published. Required fields are marked *

Pin It on Pinterest

Share This

Share this post with your friends!