45
45
import java .io .ObjectOutputStream ;
46
46
import java .io .ObjectStreamField ;
47
47
import java .io .Serializable ;
48
+ import java .text .DateFormat ;
48
49
import java .text .MessageFormat ;
49
50
import java .util .concurrent .ConcurrentHashMap ;
50
51
import java .util .spi .LocaleNameProvider ;
258
259
* locales. For example, {@code Locale.US} is the {@code Locale} object
259
260
* for the United States.
260
261
*
262
+ * <h3><a id="default_locale">Default Locale</a></h3>
263
+ *
264
+ * <p>The default Locale is provided for any locale-sensitive methods if no
265
+ * {@code Locale} is explicitly specified as an argument, such as
266
+ * {@link DateFormat#getInstance()}. The default Locale is determined at startup
267
+ * of the Java runtime and established in the following three phases:
268
+ * <ol>
269
+ * <li>The locale-related system properties listed below are established from the
270
+ * host environment. Some system properties (except for {@code user.language}) may
271
+ * not have values from the host environment.
272
+ * <table class="striped">
273
+ * <caption style="display:none">Shows property keys and associated values</caption>
274
+ * <thead>
275
+ * <tr><th scope="col">Locale-related System Properties Key</th>
276
+ * <th scope="col">Description</th></tr>
277
+ * </thead>
278
+ * <tbody>
279
+ * <tr><th scope="row">{@systemProperty user.language}</th>
280
+ * <td>{@link ##def_language language} for the default Locale,
281
+ * such as "en" (English)</td></tr>
282
+ * <tr><th scope="row">{@systemProperty user.script}</th>
283
+ * <td>{@link ##def_script script} for the default Locale,
284
+ * such as "Latn" (Latin)</td></tr>
285
+ * <tr><th scope="row">{@systemProperty user.country}</th>
286
+ * <td>{@link ##def_region country} for the default Locale,
287
+ * such as "US" (United States)</td></tr>
288
+ * <tr><th scope="row">{@systemProperty user.variant}</th>
289
+ * <td>{@link ##def_variant variant} for the default Locale,
290
+ * such as "POSIX"</td></tr>
291
+ * <tr><th scope="row">{@systemProperty user.extensions}</th>
292
+ * <td>{@link ##def_extensions extensions} for the default Locale,
293
+ * such as "u-ca-japanese" (Japanese Calendar)</td></tr>
294
+ * </tbody>
295
+ * </table>
296
+ * </li>
297
+ * <li>The values of these system properties can be overridden by values designated
298
+ * at startup time. If the overriding value of the {@code user.extensions} property
299
+ * is unparsable, it is ignored. The overriding values of other properties are not
300
+ * checked for syntax or validity and are used directly in the default Locale.
301
+ * (Typically, system property values can be provided using the {@code -D} command-line
302
+ * option of a launcher. For example, specifying {@code -Duser.extensions=foobarbaz}
303
+ * results in a default Locale with no extensions, while specifying
304
+ * {@code -Duser.language=foobarbaz} results in a default Locale whose language is
305
+ * "foobarbaz".)
306
+ * </li>
307
+ * <li>The default {@code Locale} instance is constructed from the values of these
308
+ * system properties.
309
+ * </li>
310
+ * </ol>
311
+ * <p>Altering the system property values with {@link System#setProperties(Properties)}/
312
+ * {@link System#setProperty(String, String)} has no effect on the default Locale.
313
+ * <p>Once the default Locale is established, applications can query the default
314
+ * Locale with {@link #getDefault()} and change it with {@link #setDefault(Locale)}.
315
+ * If the default Locale is changed with {@link #setDefault(Locale)}, the corresponding
316
+ * system properties are not altered. It is not recommended that applications read
317
+ * these system properties and parse or interpret them as their values may be out of date.
318
+ *
319
+ * <p>There are finer-grained default Locales specific for each {@link Locale.Category}.
320
+ * These category specific default Locales can be queried by {@link #getDefault(Category)},
321
+ * and set by {@link #setDefault(Category, Locale)}. Construction of these category
322
+ * specific default Locales are determined by the corresponding system properties,
323
+ * which consist of the base system properties as listed above, suffixed by either
324
+ * {@code ".display"} or {@code ".format"} depending on the category. For example,
325
+ * the value of the {@code user.language.display} system property will be used in the
326
+ * {@code language} part of the default Locale for the {@link Locale.Category#DISPLAY}
327
+ * category. In the absence of category specific system properties, the "category-less"
328
+ * system properties are used, such as {@code user.language} in the previous example.
329
+ *
261
330
* <h3><a id="LocaleMatching">Locale Matching</a></h3>
262
331
*
263
332
* <p>If an application or a system is internationalized and provides localized
@@ -984,14 +1053,14 @@ public int hashCode() {
984
1053
}
985
1054
986
1055
/**
987
- * Gets the current value of the default locale for this instance
988
- * of the Java Virtual Machine.
1056
+ * Gets the current value of the {@link ##default_locale default locale} for
1057
+ * this instance of the Java Virtual Machine.
989
1058
* <p>
990
1059
* The Java Virtual Machine sets the default locale during startup
991
1060
* based on the host environment. It is used by many locale-sensitive
992
1061
* methods if no locale is explicitly specified.
993
1062
* It can be changed using the
994
- * {@link #setDefault(java.util. Locale) setDefault } method.
1063
+ * {@link #setDefault(Locale)} method.
995
1064
*
996
1065
* @return the default locale for this instance of the Java Virtual Machine
997
1066
*/
@@ -1001,13 +1070,13 @@ public static Locale getDefault() {
1001
1070
}
1002
1071
1003
1072
/**
1004
- * Gets the current value of the default locale for the specified Category
1005
- * for this instance of the Java Virtual Machine.
1073
+ * Gets the current value of the {@link ##default_locale default locale} for
1074
+ * the specified Category for this instance of the Java Virtual Machine.
1006
1075
* <p>
1007
1076
* The Java Virtual Machine sets the default locale during startup based
1008
1077
* on the host environment. It is used by many locale-sensitive methods
1009
1078
* if no locale is explicitly specified. It can be changed using the
1010
- * setDefault(Locale.Category, Locale) method.
1079
+ * {@link # setDefault(Locale.Category, Locale)} method.
1011
1080
*
1012
1081
* @param category the specified category to get the default locale
1013
1082
* @throws NullPointerException if category is null
@@ -1108,8 +1177,9 @@ private static Optional<LocaleExtensions> getDefaultExtensions(String extensions
1108
1177
}
1109
1178
1110
1179
/**
1111
- * Sets the default locale for this instance of the Java Virtual Machine.
1112
- * This does not affect the host locale.
1180
+ * Sets the {@link ##default_locale default locale} for
1181
+ * this instance of the Java Virtual Machine. This does not affect the
1182
+ * host locale.
1113
1183
* <p>
1114
1184
* If there is a security manager, its {@code checkPermission}
1115
1185
* method is called with a {@code PropertyPermission("user.language", "write")}
@@ -1142,8 +1212,9 @@ public static synchronized void setDefault(Locale newLocale) {
1142
1212
}
1143
1213
1144
1214
/**
1145
- * Sets the default locale for the specified Category for this instance
1146
- * of the Java Virtual Machine. This does not affect the host locale.
1215
+ * Sets the {@link ##default_locale default locale} for the specified
1216
+ * Category for this instance of the Java Virtual Machine. This does
1217
+ * not affect the host locale.
1147
1218
* <p>
1148
1219
* If there is a security manager, its checkPermission method is called
1149
1220
* with a PropertyPermission("user.language", "write") permission before
0 commit comments