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