• Menu
  • Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

JavaBeat

Java Tutorial Blog

  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)
  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)

How To Set Default Locale In Java

January 31, 2014 //  by Krishna Srinivasan//  Leave a Comment

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.

DefaultLocaleExample.java

package javabeat.net.core;

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");
		Locale.setDefault(indiaLocale);

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

Output…

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

Category: JavaTag: Java Basics

About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Previous Post: « Servlet Context
Next Post: How To Display Environment Variables In Java »

Reader Interactions

Leave a Reply Cancel reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Follow Us

  • Facebook
  • Pinterest

FEATURED TUTORIALS

EJB 3.0 Timer Services

What is new in Java 6.0 Collections API?

The Java 6.0 Compiler API

Introductiion to Jakarta Struts

What’s new in Struts 2.0? – Struts 2.0 Framework

JavaBeat

Copyright © by JavaBeat · All rights reserved
Privacy Policy | Contact