The JavaTM Tutorial

| Start of Tutorial > Start of Trail > Start of Lesson | Search Feedback Form

Trail: Internationalization
Lesson: Setting the Locale

## The Scope of a Locale

> The Java platform does not require you to use the same `Locale` throughout your program. If you wish, you can assign a different `Locale` to every locale-sensitive object in your program. This flexibility allows you to develop multilingual applications, which can display information in multiple languages.

> However, most applications are not multi-lingual and their locale-sensitive objects rely on the default `Locale`. Set by the Java Virtual Machine when it starts up, the default `Locale` corresponds to the locale of the host platform. To determine the default `Locale` of your Java Virtual Machine, invoke the `Locale.getDefault` method. You should not set the default `Locale` programmatically because it is shared by all locale-sensitive classes.

> Distributed computing raises some interesting issues. For example, suppose you are designing an application server that will receive requests from clients in various countries. If the `Locale` for each client is different, what should be the `Locale` of the server? Perhaps the server is multithreaded, with each thread set to the `Locale` of the client it services. Or perhaps all data passed between the server and the clients should be locale-independent.

> Which design approach should you take? If possible, the data passed between the server and the clients should be locale-independent. This simplifies the design of the server by making the clients responsible for displaying the data in a locale-sensitive manner. However, this approach won't work if the server must store the data in a locale-specific form. For example, the server might store Spanish, English, and French versions of the same data in different database columns. In this case, the server might want to query the client for its `Locale`, since the `Locale` may have changed since the last request.

| Start of Tutorial > Start of Trail > Start of Lesson | Search Feedback Form

Copyright 1995-2001 Sun Microsystems, Inc. All rights reserved.