001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      https://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.lang3;
018
019import java.io.File;
020import java.nio.file.Path;
021import java.nio.file.Paths;
022
023/**
024 * Helpers for {@link System}.
025 *
026 * <p>
027 * If a system property cannot be read due to security restrictions, the corresponding field in this class will be set to {@code null} and a message will be
028 * written to {@code System.err}.
029 * </p>
030 * <p>
031 * #ThreadSafe#
032 * </p>
033 *
034 * @since 1.0
035 * @see SystemProperties
036 */
037public class SystemUtils {
038
039    /**
040     * The prefix String for all Windows OS.
041     */
042    private static final String OS_NAME_WINDOWS_PREFIX = "Windows";
043
044    // System property constants
045    // -----------------------------------------------------------------------
046    // These MUST be declared first. Other constants depend on this.
047
048    /**
049     * A constant for the System Property {@code file.encoding}.
050     *
051     * <p>
052     * File encoding, such as {@code Cp1252}.
053     * </p>
054     * <p>
055     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist.
056     * </p>
057     * <p>
058     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is
059     * called after this class is loaded, the value will be out of sync with that System property.
060     * </p>
061     *
062     * @see SystemProperties#getFileEncoding()
063     * @since 2.0
064     * @since Java 1.2
065     */
066    public static final String FILE_ENCODING = SystemProperties.getFileEncoding();
067
068    /**
069     * A constant for the System Property {@code file.separator}.
070     * <p>
071     * The file separator is:
072     * </p>
073     * <ul>
074     * <li>{@code "/"} on Unix</li>
075     * <li>{@code "\"} on Windows.</li>
076     * </ul>
077     *
078     * <p>
079     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist.
080     * </p>
081     * <p>
082     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is
083     * called after this class is loaded, the value will be out of sync with that System property.
084     * </p>
085     *
086     * @see SystemProperties#getFileSeparator()
087     * @deprecated Use {@link File#separator}, since it is guaranteed to be a string containing a single character and it does not require a privilege check.
088     * @since Java 1.1
089     */
090    @Deprecated
091    public static final String FILE_SEPARATOR = SystemProperties.getFileSeparator();
092
093    /**
094     * A constant for the System Property {@code java.awt.fonts}.
095     *
096     * <p>
097     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist.
098     * </p>
099     * <p>
100     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is
101     * called after this class is loaded, the value will be out of sync with that System property.
102     * </p>
103     *
104     * @see SystemProperties#getJavaAwtFonts()
105     * @since 2.1
106     * @deprecated Deprecated without replacement.
107     */
108    @Deprecated
109    public static final String JAVA_AWT_FONTS = SystemProperties.getJavaAwtFonts();
110
111    /**
112     * A constant for the System Property {@code java.awt.graphicsenv}.
113     *
114     * <p>
115     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist.
116     * </p>
117     * <p>
118     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is
119     * called after this class is loaded, the value will be out of sync with that System property.
120     * </p>
121     *
122     * @see SystemProperties#getJavaAwtGraphicsenv()
123     * @since 2.1
124     * @deprecated Deprecated without replacement.
125     */
126    @Deprecated
127    public static final String JAVA_AWT_GRAPHICSENV = SystemProperties.getJavaAwtGraphicsenv();
128
129    /**
130     * A constant for the System Property {@code java.awt.headless}. The value of this property is the String {@code "true"} or {@code "false"}.
131     *
132     * <p>
133     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist.
134     * </p>
135     * <p>
136     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is
137     * called after this class is loaded, the value will be out of sync with that System property.
138     * </p>
139     *
140     * @see #isJavaAwtHeadless()
141     * @see SystemProperties#getJavaAwtHeadless()
142     * @since 2.1
143     * @since Java 1.4
144     * @deprecated Deprecated without replacement.
145     */
146    @Deprecated
147    public static final String JAVA_AWT_HEADLESS = SystemProperties.getJavaAwtHeadless();
148
149    /**
150     * A constant for the System Property {@code java.awt.printerjob}.
151     *
152     * <p>
153     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist.
154     * </p>
155     * <p>
156     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is
157     * called after this class is loaded, the value will be out of sync with that System property.
158     * </p>
159     *
160     * @see SystemProperties#getJavaAwtPrinterjob()
161     * @since 2.1
162     * @deprecated Deprecated without replacement.
163     */
164    @Deprecated
165    public static final String JAVA_AWT_PRINTERJOB = SystemProperties.getJavaAwtPrinterjob();
166
167    /**
168     * A constant for the System Property {@code java.class.path}. Java class path.
169     *
170     * <p>
171     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist.
172     * </p>
173     * <p>
174     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is
175     * called after this class is loaded, the value will be out of sync with that System property.
176     * </p>
177     *
178     * @see SystemProperties#getJavaClassPath()
179     * @since Java 1.1
180     */
181    public static final String JAVA_CLASS_PATH = SystemProperties.getJavaClassPath();
182
183    /**
184     * A constant for the System Property {@code java.class.version}. Java class format version number.
185     *
186     * <p>
187     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist.
188     * </p>
189     * <p>
190     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is
191     * called after this class is loaded, the value will be out of sync with that System property.
192     * </p>
193     *
194     * @see SystemProperties#getJavaClassVersion()
195     * @since Java 1.1
196     */
197    public static final String JAVA_CLASS_VERSION = SystemProperties.getJavaClassVersion();
198
199    /**
200     * A constant for the System Property {@code java.compiler}. Name of JIT compiler to use. First in JDK version 1.2. Not used in Sun JDKs after 1.2.
201     *
202     * <p>
203     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist.
204     * </p>
205     * <p>
206     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is
207     * called after this class is loaded, the value will be out of sync with that System property.
208     * </p>
209     *
210     * @see SystemProperties#getJavaCompiler()
211     * @since Java 1.2. Not used in Sun versions after 1.2.
212     * @deprecated Deprecated without replacement; see https://bugs.openjdk.org/browse/JDK-8305998
213     */
214    @Deprecated
215    public static final String JAVA_COMPILER = SystemProperties.getJavaCompiler();
216
217    /**
218     * A constant for the System Property {@code java.endorsed.dirs}. Path of endorsed directory or directories.
219     *
220     * <p>
221     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist.
222     * </p>
223     * <p>
224     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is
225     * called after this class is loaded, the value will be out of sync with that System property.
226     * </p>
227     *
228     * @see SystemProperties#getJavaEndorsedDirs()
229     * @since Java 1.4
230     * @deprecated Deprecated without replacement.
231     */
232    @Deprecated
233    public static final String JAVA_ENDORSED_DIRS = SystemProperties.getJavaEndorsedDirs();
234
235    /**
236     * A constant for the System Property {@code java.ext.dirs}. Path of extension directory or directories.
237     *
238     * <p>
239     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist.
240     * </p>
241     * <p>
242     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is
243     * called after this class is loaded, the value will be out of sync with that System property.
244     * </p>
245     *
246     * @see SystemProperties#getJavaExtDirs()
247     * @since Java 1.3
248     * @deprecated Deprecated without replacement.
249     */
250    @Deprecated
251    public static final String JAVA_EXT_DIRS = SystemProperties.getJavaExtDirs();
252
253    /**
254     * A constant for the System Property {@code java.home}. Java installation directory.
255     *
256     * <p>
257     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist.
258     * </p>
259     * <p>
260     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is
261     * called after this class is loaded, the value will be out of sync with that System property.
262     * </p>
263     *
264     * @see SystemProperties#getJavaHome()
265     * @since Java 1.1
266     */
267    public static final String JAVA_HOME = SystemProperties.getJavaHome();
268
269    /**
270     * A constant for the System Property {@code java.io.tmpdir}. Default temp file path.
271     *
272     * <p>
273     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist.
274     * </p>
275     * <p>
276     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is
277     * called after this class is loaded, the value will be out of sync with that System property.
278     * </p>
279     *
280     * @see SystemProperties#getJavaIoTmpdir()
281     * @since Java 1.2
282     */
283    public static final String JAVA_IO_TMPDIR = SystemProperties.getJavaIoTmpdir();
284
285    /**
286     * A constant for the System Property {@code java.library.path}. List of paths to search when loading libraries.
287     *
288     * <p>
289     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist.
290     * </p>
291     * <p>
292     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is
293     * called after this class is loaded, the value will be out of sync with that System property.
294     * </p>
295     *
296     * @see SystemProperties#getJavaLibraryPath()
297     * @since Java 1.2
298     */
299    public static final String JAVA_LIBRARY_PATH = SystemProperties.getJavaLibraryPath();
300
301    /**
302     * A constant for the System Property {@code java.runtime.name}. Java Runtime Environment name.
303     *
304     * <p>
305     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist.
306     * </p>
307     * <p>
308     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is
309     * called after this class is loaded, the value will be out of sync with that System property.
310     * </p>
311     *
312     * @see SystemProperties#getJavaRuntimeName()
313     * @since 2.0
314     * @since Java 1.3
315     */
316    public static final String JAVA_RUNTIME_NAME = SystemProperties.getJavaRuntimeName();
317
318    /**
319     * A constant for the System Property {@code java.runtime.version}. Java Runtime Environment version.
320     *
321     * <p>
322     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist.
323     * </p>
324     * <p>
325     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is
326     * called after this class is loaded, the value will be out of sync with that System property.
327     * </p>
328     *
329     * @see SystemProperties#getJavaRuntimeVersion()
330     * @since 2.0
331     * @since Java 1.3
332     */
333    public static final String JAVA_RUNTIME_VERSION = SystemProperties.getJavaRuntimeVersion();
334
335    /**
336     * A constant for the System Property {@code java.specification.name}. Java Runtime Environment specification name.
337     *
338     * <p>
339     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist.
340     * </p>
341     * <p>
342     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is
343     * called after this class is loaded, the value will be out of sync with that System property.
344     * </p>
345     *
346     * @see SystemProperties#getJavaSpecificationName()
347     * @since Java 1.2
348     */
349    public static final String JAVA_SPECIFICATION_NAME = SystemProperties.getJavaSpecificationName();
350
351    /**
352     * A constant for the System Property {@code java.specification.vendor}. Java Runtime Environment specification vendor.
353     *
354     * <p>
355     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist.
356     * </p>
357     * <p>
358     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is
359     * called after this class is loaded, the value will be out of sync with that System property.
360     * </p>
361     *
362     * @see SystemProperties#getJavaSpecificationVendor()
363     * @since Java 1.2
364     */
365    public static final String JAVA_SPECIFICATION_VENDOR = SystemProperties.getJavaSpecificationVendor();
366
367    /**
368     * A constant for the System Property {@code java.specification.version}. Java Runtime Environment specification version.
369     *
370     * <p>
371     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist.
372     * </p>
373     * <p>
374     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is
375     * called after this class is loaded, the value will be out of sync with that System property.
376     * </p>
377     *
378     * @see SystemProperties#getJavaSpecificationVersion()
379     * @since Java 1.3
380     */
381    public static final String JAVA_SPECIFICATION_VERSION = SystemProperties.getJavaSpecificationVersion();
382
383    private static final JavaVersion JAVA_SPECIFICATION_VERSION_AS_ENUM = JavaVersion.get(JAVA_SPECIFICATION_VERSION);
384
385    /**
386     * A constant for the System Property {@code java.util.prefs.PreferencesFactory}. A class name.
387     *
388     * <p>
389     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist.
390     * </p>
391     * <p>
392     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is
393     * called after this class is loaded, the value will be out of sync with that System property.
394     * </p>
395     *
396     * @see SystemProperties#getJavaUtilPrefsPreferencesFactory()
397     * @since 2.1
398     * @since Java 1.4
399     */
400    public static final String JAVA_UTIL_PREFS_PREFERENCES_FACTORY = SystemProperties.getJavaUtilPrefsPreferencesFactory();
401
402    /**
403     * A constant for the System Property {@code java.vendor}. Java vendor-specific string.
404     *
405     * <p>
406     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist.
407     * </p>
408     * <p>
409     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is
410     * called after this class is loaded, the value will be out of sync with that System property.
411     * </p>
412     *
413     * @see SystemProperties#getJavaVendor()
414     * @since Java 1.1
415     */
416    public static final String JAVA_VENDOR = SystemProperties.getJavaVendor();
417
418    /**
419     * A constant for the System Property {@code java.vendor.url}. Java vendor URL.
420     *
421     * <p>
422     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist.
423     * </p>
424     * <p>
425     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is
426     * called after this class is loaded, the value will be out of sync with that System property.
427     * </p>
428     *
429     * @see SystemProperties#getJavaVendorUrl()
430     * @since Java 1.1
431     */
432    public static final String JAVA_VENDOR_URL = SystemProperties.getJavaVendorUrl();
433
434    /**
435     * A constant for the System Property {@code java.version}. Java version number.
436     *
437     * <p>
438     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist.
439     * </p>
440     * <p>
441     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is
442     * called after this class is loaded, the value will be out of sync with that System property.
443     * </p>
444     *
445     * @see SystemProperties#getJavaVersion()
446     * @since Java 1.1
447     */
448    public static final String JAVA_VERSION = SystemProperties.getJavaVersion();
449
450    /**
451     * A constant for the System Property {@code java.vm.info}. Java Virtual Machine implementation info.
452     *
453     * <p>
454     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist.
455     * </p>
456     * <p>
457     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is
458     * called after this class is loaded, the value will be out of sync with that System property.
459     * </p>
460     *
461     * @see SystemProperties#getJavaVmInfo()
462     * @since 2.0
463     * @since Java 1.2
464     */
465    public static final String JAVA_VM_INFO = SystemProperties.getJavaVmInfo();
466
467    /**
468     * A constant for the System Property {@code java.vm.name}. Java Virtual Machine implementation name.
469     *
470     * <p>
471     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist.
472     * </p>
473     * <p>
474     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is
475     * called after this class is loaded, the value will be out of sync with that System property.
476     * </p>
477     *
478     * @see SystemProperties#getJavaVmName()
479     * @since Java 1.2
480     */
481    public static final String JAVA_VM_NAME = SystemProperties.getJavaVmName();
482
483    /**
484     * A constant for the System Property {@code java.vm.specification.name}. Java Virtual Machine specification name.
485     *
486     * <p>
487     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist.
488     * </p>
489     * <p>
490     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is
491     * called after this class is loaded, the value will be out of sync with that System property.
492     * </p>
493     *
494     * @see SystemProperties#getJavaVmSpecificationName()
495     * @since Java 1.2
496     */
497    public static final String JAVA_VM_SPECIFICATION_NAME = SystemProperties.getJavaVmSpecificationName();
498
499    /**
500     * A constant for the System Property {@code java.vm.specification.vendor}. Java Virtual Machine specification vendor.
501     *
502     * <p>
503     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist.
504     * </p>
505     * <p>
506     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is
507     * called after this class is loaded, the value will be out of sync with that System property.
508     * </p>
509     *
510     * @see SystemProperties#getJavaVmSpecificationVendor()
511     * @since Java 1.2
512     */
513    public static final String JAVA_VM_SPECIFICATION_VENDOR = SystemProperties.getJavaVmSpecificationVendor();
514
515    /**
516     * A constant for the System Property {@code java.vm.specification.version}. Java Virtual Machine specification version.
517     *
518     * <p>
519     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist.
520     * </p>
521     * <p>
522     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is
523     * called after this class is loaded, the value will be out of sync with that System property.
524     * </p>
525     *
526     * @see SystemProperties#getJavaVmSpecificationVersion()
527     * @since Java 1.2
528     */
529    public static final String JAVA_VM_SPECIFICATION_VERSION = SystemProperties.getJavaVmSpecificationVersion();
530
531    /**
532     * A constant for the System Property {@code java.vm.vendor}. Java Virtual Machine implementation vendor.
533     *
534     * <p>
535     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist.
536     * </p>
537     * <p>
538     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is
539     * called after this class is loaded, the value will be out of sync with that System property.
540     * </p>
541     *
542     * @see SystemProperties#getJavaVmVendor()
543     * @since Java 1.2
544     */
545    public static final String JAVA_VM_VENDOR = SystemProperties.getJavaVmVendor();
546
547    /**
548     * A constant for the System Property {@code java.vm.version}. Java Virtual Machine implementation version.
549     *
550     * <p>
551     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist.
552     * </p>
553     * <p>
554     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is
555     * called after this class is loaded, the value will be out of sync with that System property.
556     * </p>
557     *
558     * @see SystemProperties#getJavaVmVersion()
559     * @since Java 1.2
560     */
561    public static final String JAVA_VM_VERSION = SystemProperties.getJavaVmVersion();
562
563    /**
564     * A constant for the System Property {@code line.separator}. Line separator ({@code &quot;\n&quot;} on Unix).
565     *
566     * <p>
567     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist.
568     * </p>
569     * <p>
570     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is
571     * called after this class is loaded, the value will be out of sync with that System property.
572     * </p>
573     *
574     * @see SystemProperties#getLineSeparator()
575     * @since Java 1.1
576     * @deprecated Use {@link System#lineSeparator()} instead, since it does not require a privilege check.
577     */
578    @Deprecated
579    public static final String LINE_SEPARATOR = SystemProperties.getLineSeparator();
580
581    /**
582     * A constant for the System Property {@code os.arch}. Operating system architecture.
583     *
584     * <p>
585     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist.
586     * </p>
587     * <p>
588     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is
589     * called after this class is loaded, the value will be out of sync with that System property.
590     * </p>
591     *
592     * @see SystemProperties#getOsArch()
593     * @since Java 1.1
594     */
595    public static final String OS_ARCH = SystemProperties.getOsArch();
596
597    /**
598     * A constant for the System Property {@code os.name}. Operating system name.
599     *
600     * <p>
601     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist.
602     * </p>
603     * <p>
604     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is
605     * called after this class is loaded, the value will be out of sync with that System property.
606     * </p>
607     *
608     * @see SystemProperties#getOsName()
609     * @since Java 1.1
610     */
611    public static final String OS_NAME = SystemProperties.getOsName();
612
613    /**
614     * A constant for the System Property {@code os.version}. Operating system version.
615     *
616     * <p>
617     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist.
618     * </p>
619     * <p>
620     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is
621     * called after this class is loaded, the value will be out of sync with that System property.
622     * </p>
623     *
624     * @see SystemProperties#getOsVersion()
625     * @since Java 1.1
626     */
627    public static final String OS_VERSION = SystemProperties.getOsVersion();
628
629    /**
630     * A constant for the System Property {@code path.separator}. Path separator ({@code &quot;:&quot;} on Unix).
631     *
632     * <p>
633     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist.
634     * </p>
635     * <p>
636     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is
637     * called after this class is loaded, the value will be out of sync with that System property.
638     * </p>
639     *
640     * @see SystemProperties#getPathSeparator()
641     * @since Java 1.1
642     * @deprecated Use {@link File#pathSeparator}, since it is guaranteed to be a string containing a single character and it does not require a privilege
643     *             check.
644     */
645    @Deprecated
646    public static final String PATH_SEPARATOR = SystemProperties.getPathSeparator();
647
648    /**
649     * A constant for the System Property {@code user.country} or {@code user.region}. User's country code, such as {@code "GB"}. First in Java version 1.2 as
650     * {@code user.region}. Renamed to {@code user.country} in 1.4
651     *
652     * <p>
653     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist.
654     * </p>
655     * <p>
656     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is
657     * called after this class is loaded, the value will be out of sync with that System property.
658     * </p>
659     *
660     * @since 2.0
661     * @since Java 1.2
662     */
663    public static final String USER_COUNTRY = SystemProperties.getProperty(SystemProperties.USER_COUNTRY,
664            () -> SystemProperties.getProperty(SystemProperties.USER_REGION));
665
666    /**
667     * A constant for the System Property {@code user.dir}. User's current working directory.
668     *
669     * <p>
670     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist.
671     * </p>
672     * <p>
673     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is
674     * called after this class is loaded, the value will be out of sync with that System property.
675     * </p>
676     *
677     * @see SystemProperties#getUserDir()
678     * @since Java 1.1
679     */
680    public static final String USER_DIR = SystemProperties.getUserDir();
681
682    /**
683     * A constant for the System Property {@code user.home}. User's home directory.
684     *
685     * <p>
686     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist.
687     * </p>
688     * <p>
689     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is
690     * called after this class is loaded, the value will be out of sync with that System property.
691     * </p>
692     *
693     * @see SystemProperties#getUserHome()
694     * @since Java 1.1
695     */
696    public static final String USER_HOME = SystemProperties.getUserHome();
697
698    /**
699     * A constant for the System Property {@code user.language}. User's language code, such as {@code "en"}.
700     *
701     * <p>
702     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist.
703     * </p>
704     * <p>
705     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is
706     * called after this class is loaded, the value will be out of sync with that System property.
707     * </p>
708     *
709     * @see SystemProperties#getUserLanguage()
710     * @since 2.0
711     * @since Java 1.2
712     */
713    public static final String USER_LANGUAGE = SystemProperties.getUserLanguage();
714
715    /**
716     * A constant for the System Property {@code user.name}. User's account name.
717     *
718     * <p>
719     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist.
720     * </p>
721     * <p>
722     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is
723     * called after this class is loaded, the value will be out of sync with that System property.
724     * </p>
725     *
726     * @see SystemProperties#getUserName()
727     * @since Java 1.1
728     */
729    public static final String USER_NAME = SystemProperties.getUserName();
730
731    /**
732     * A constant for the System Property {@code user.timezone}. For example: {@code "America/Los_Angeles"}.
733     *
734     * <p>
735     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist.
736     * </p>
737     * <p>
738     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is
739     * called after this class is loaded, the value will be out of sync with that System property.
740     * </p>
741     *
742     * @see SystemProperties#getUserTimezone()
743     * @since 2.1
744     */
745    public static final String USER_TIMEZONE = SystemProperties.getUserTimezone();
746
747    // Java version checks
748    // -----------------------------------------------------------------------
749    // These MUST be declared after those above as they depend on the
750    // values being set up
751
752    /**
753     * The constant {@code true} if this is Java version 1.1 (also 1.1.x versions).
754     * <p>
755     * The result depends on the value of the {@link #JAVA_SPECIFICATION_VERSION} constant.
756     * </p>
757     * <p>
758     * The field will return {@code false} if {@link #JAVA_SPECIFICATION_VERSION} is {@code null}.
759     * </p>
760     * <p>
761     * This value is initialized when the class is loaded.
762     * </p>
763     */
764    public static final boolean IS_JAVA_1_1 = getJavaVersionMatches("1.1");
765
766    /**
767     * The constant {@code true} if this is Java version 1.2 (also 1.2.x versions).
768     * <p>
769     * The result depends on the value of the {@link #JAVA_SPECIFICATION_VERSION} constant.
770     * </p>
771     * <p>
772     * The field will return {@code false} if {@link #JAVA_SPECIFICATION_VERSION} is {@code null}.
773     * </p>
774     * <p>
775     * This value is initialized when the class is loaded.
776     * </p>
777     */
778    public static final boolean IS_JAVA_1_2 = getJavaVersionMatches("1.2");
779
780    /**
781     * The constant {@code true} if this is Java version 1.3 (also 1.3.x versions).
782     * <p>
783     * The result depends on the value of the {@link #JAVA_SPECIFICATION_VERSION} constant.
784     * </p>
785     * <p>
786     * The field will return {@code false} if {@link #JAVA_SPECIFICATION_VERSION} is {@code null}.
787     * </p>
788     * <p>
789     * This value is initialized when the class is loaded.
790     * </p>
791     */
792    public static final boolean IS_JAVA_1_3 = getJavaVersionMatches("1.3");
793
794    /**
795     * The constant {@code true} if this is Java version 1.4 (also 1.4.x versions).
796     * <p>
797     * The result depends on the value of the {@link #JAVA_SPECIFICATION_VERSION} constant.
798     * </p>
799     * <p>
800     * The field will return {@code false} if {@link #JAVA_SPECIFICATION_VERSION} is {@code null}.
801     * </p>
802     * <p>
803     * This value is initialized when the class is loaded.
804     * </p>
805     */
806    public static final boolean IS_JAVA_1_4 = getJavaVersionMatches("1.4");
807
808    /**
809     * The constant {@code true} if this is Java version 1.5 (also 1.5.x versions).
810     * <p>
811     * The result depends on the value of the {@link #JAVA_SPECIFICATION_VERSION} constant.
812     * </p>
813     * <p>
814     * The field will return {@code false} if {@link #JAVA_SPECIFICATION_VERSION} is {@code null}.
815     * </p>
816     * <p>
817     * This value is initialized when the class is loaded.
818     * </p>
819     */
820    public static final boolean IS_JAVA_1_5 = getJavaVersionMatches("1.5");
821
822    /**
823     * The constant {@code true} if this is Java version 1.6 (also 1.6.x versions).
824     * <p>
825     * The result depends on the value of the {@link #JAVA_SPECIFICATION_VERSION} constant.
826     * </p>
827     * <p>
828     * The field will return {@code false} if {@link #JAVA_SPECIFICATION_VERSION} is {@code null}.
829     * </p>
830     * <p>
831     * This value is initialized when the class is loaded.
832     * </p>
833     */
834    public static final boolean IS_JAVA_1_6 = getJavaVersionMatches("1.6");
835
836    /**
837     * The constant {@code true} if this is Java version 1.7 (also 1.7.x versions).
838     * <p>
839     * The result depends on the value of the {@link #JAVA_SPECIFICATION_VERSION} constant.
840     * </p>
841     * <p>
842     * The field will return {@code false} if {@link #JAVA_SPECIFICATION_VERSION} is {@code null}.
843     * </p>
844     * <p>
845     * This value is initialized when the class is loaded.
846     * </p>
847     *
848     * @since 3.0
849     */
850    public static final boolean IS_JAVA_1_7 = getJavaVersionMatches("1.7");
851
852    /**
853     * The constant {@code true} if this is Java version 1.8 (also 1.8.x versions).
854     * <p>
855     * The result depends on the value of the {@link #JAVA_SPECIFICATION_VERSION} constant.
856     * </p>
857     * <p>
858     * The field will return {@code false} if {@link #JAVA_SPECIFICATION_VERSION} is {@code null}.
859     * </p>
860     * <p>
861     * This value is initialized when the class is loaded.
862     * </p>
863     *
864     * @since 3.3.2
865     */
866    public static final boolean IS_JAVA_1_8 = getJavaVersionMatches("1.8");
867
868    /**
869     * The constant {@code true} if this is Java version 1.9 (also 1.9.x versions).
870     * <p>
871     * The result depends on the value of the {@link #JAVA_SPECIFICATION_VERSION} constant.
872     * </p>
873     * <p>
874     * The field will return {@code false} if {@link #JAVA_SPECIFICATION_VERSION} is {@code null}.
875     * </p>
876     * <p>
877     * This value is initialized when the class is loaded.
878     * </p>
879     *
880     * @since 3.4
881     * @deprecated As of release 3.5, replaced by {@link #IS_JAVA_9}.
882     */
883    @Deprecated
884    public static final boolean IS_JAVA_1_9 = getJavaVersionMatches("9");
885
886    /**
887     * The constant {@code true} if this is Java version 9 (also 9.x versions).
888     * <p>
889     * The result depends on the value of the {@link #JAVA_SPECIFICATION_VERSION} constant.
890     * </p>
891     * <p>
892     * The field will return {@code false} if {@link #JAVA_SPECIFICATION_VERSION} is {@code null}.
893     * </p>
894     * <p>
895     * This value is initialized when the class is loaded.
896     * </p>
897     *
898     * @since 3.5
899     */
900    public static final boolean IS_JAVA_9 = getJavaVersionMatches("9");
901
902    /**
903     * The constant {@code true} if this is Java version 10 (also 10.x versions).
904     * <p>
905     * The result depends on the value of the {@link #JAVA_SPECIFICATION_VERSION} constant.
906     * </p>
907     * <p>
908     * The field will return {@code false} if {@link #JAVA_SPECIFICATION_VERSION} is {@code null}.
909     * </p>
910     * <p>
911     * This value is initialized when the class is loaded.
912     * </p>
913     *
914     * @since 3.7
915     */
916    public static final boolean IS_JAVA_10 = getJavaVersionMatches("10");
917
918    /**
919     * The constant {@code true} if this is Java version 11 (also 11.x versions).
920     * <p>
921     * The result depends on the value of the {@link #JAVA_SPECIFICATION_VERSION} constant.
922     * </p>
923     * <p>
924     * The field will return {@code false} if {@link #JAVA_SPECIFICATION_VERSION} is {@code null}.
925     * </p>
926     * <p>
927     * This value is initialized when the class is loaded.
928     * </p>
929     *
930     * @since 3.8
931     */
932    public static final boolean IS_JAVA_11 = getJavaVersionMatches("11");
933
934    /**
935     * The constant {@code true} if this is Java version 12 (also 12.x versions).
936     * <p>
937     * The result depends on the value of the {@link #JAVA_SPECIFICATION_VERSION} constant.
938     * </p>
939     * <p>
940     * The field will return {@code false} if {@link #JAVA_SPECIFICATION_VERSION} is {@code null}.
941     * </p>
942     * <p>
943     * This value is initialized when the class is loaded.
944     * </p>
945     *
946     * @since 3.9
947     */
948    public static final boolean IS_JAVA_12 = getJavaVersionMatches("12");
949
950    /**
951     * The constant {@code true} if this is Java version 13 (also 13.x versions).
952     * <p>
953     * The result depends on the value of the {@link #JAVA_SPECIFICATION_VERSION} constant.
954     * </p>
955     * <p>
956     * The field will return {@code false} if {@link #JAVA_SPECIFICATION_VERSION} is {@code null}.
957     * </p>
958     * <p>
959     * This value is initialized when the class is loaded.
960     * </p>
961     *
962     * @since 3.9
963     */
964    public static final boolean IS_JAVA_13 = getJavaVersionMatches("13");
965
966    /**
967     * The constant {@code true} if this is Java version 14 (also 14.x versions).
968     * <p>
969     * The result depends on the value of the {@link #JAVA_SPECIFICATION_VERSION} constant.
970     * </p>
971     * <p>
972     * The field will return {@code false} if {@link #JAVA_SPECIFICATION_VERSION} is {@code null}.
973     * </p>
974     * <p>
975     * This value is initialized when the class is loaded.
976     * </p>
977     *
978     * @since 3.10
979     */
980    public static final boolean IS_JAVA_14 = getJavaVersionMatches("14");
981
982    /**
983     * The constant {@code true} if this is Java version 15 (also 15.x versions).
984     * <p>
985     * The result depends on the value of the {@link #JAVA_SPECIFICATION_VERSION} constant.
986     * </p>
987     * <p>
988     * The field will return {@code false} if {@link #JAVA_SPECIFICATION_VERSION} is {@code null}.
989     * </p>
990     * <p>
991     * This value is initialized when the class is loaded.
992     * </p>
993     *
994     * @since 3.10
995     */
996    public static final boolean IS_JAVA_15 = getJavaVersionMatches("15");
997
998    /**
999     * The constant {@code true} if this is Java version 16 (also 16.x versions).
1000     * <p>
1001     * The result depends on the value of the {@link #JAVA_SPECIFICATION_VERSION} constant.
1002     * </p>
1003     * <p>
1004     * The field will return {@code false} if {@link #JAVA_SPECIFICATION_VERSION} is {@code null}.
1005     * </p>
1006     * <p>
1007     * This value is initialized when the class is loaded.
1008     * </p>
1009     *
1010     * @since 3.13.0
1011     */
1012    public static final boolean IS_JAVA_16 = getJavaVersionMatches("16");
1013
1014    /**
1015     * The constant {@code true} if this is Java version 17 (also 17.x versions).
1016     * <p>
1017     * The result depends on the value of the {@link #JAVA_SPECIFICATION_VERSION} constant.
1018     * </p>
1019     * <p>
1020     * The field will return {@code false} if {@link #JAVA_SPECIFICATION_VERSION} is {@code null}.
1021     * </p>
1022     * <p>
1023     * This value is initialized when the class is loaded.
1024     * </p>
1025     *
1026     * @since 3.13.0
1027     */
1028    public static final boolean IS_JAVA_17 = getJavaVersionMatches("17");
1029
1030    /**
1031     * The constant {@code true} if this is Java version 18 (also 18.x versions).
1032     * <p>
1033     * The result depends on the value of the {@link #JAVA_SPECIFICATION_VERSION} constant.
1034     * </p>
1035     * <p>
1036     * The field will return {@code false} if {@link #JAVA_SPECIFICATION_VERSION} is {@code null}.
1037     * </p>
1038     * <p>
1039     * This value is initialized when the class is loaded.
1040     * </p>
1041     *
1042     * @since 3.13.0
1043     */
1044    public static final boolean IS_JAVA_18 = getJavaVersionMatches("18");
1045
1046    /**
1047     * The constant {@code true} if this is Java version 19 (also 19.x versions).
1048     * <p>
1049     * The result depends on the value of the {@link #JAVA_SPECIFICATION_VERSION} constant.
1050     * </p>
1051     * <p>
1052     * The field will return {@code false} if {@link #JAVA_SPECIFICATION_VERSION} is {@code null}.
1053     * </p>
1054     * <p>
1055     * This value is initialized when the class is loaded.
1056     * </p>
1057     *
1058     * @since 3.13.0
1059     */
1060    public static final boolean IS_JAVA_19 = getJavaVersionMatches("19");
1061
1062    /**
1063     * The constant {@code true} if this is Java version 20 (also 20.x versions).
1064     * <p>
1065     * The result depends on the value of the {@link #JAVA_SPECIFICATION_VERSION} constant.
1066     * </p>
1067     * <p>
1068     * The field will return {@code false} if {@link #JAVA_SPECIFICATION_VERSION} is {@code null}.
1069     * </p>
1070     * <p>
1071     * This value is initialized when the class is loaded.
1072     * </p>
1073     *
1074     * @since 3.13.0
1075     */
1076    public static final boolean IS_JAVA_20 = getJavaVersionMatches("20");
1077
1078    /**
1079     * The constant {@code true} if this is Java version 21 (also 21.x versions).
1080     * <p>
1081     * The result depends on the value of the {@link #JAVA_SPECIFICATION_VERSION} constant.
1082     * </p>
1083     * <p>
1084     * The field will return {@code false} if {@link #JAVA_SPECIFICATION_VERSION} is {@code null}.
1085     * </p>
1086     * <p>
1087     * This value is initialized when the class is loaded.
1088     * </p>
1089     *
1090     * @since 3.13.0
1091     */
1092    public static final boolean IS_JAVA_21 = getJavaVersionMatches("21");
1093
1094    /**
1095     * The constant {@code true} if this is Java version 22 (also 22.x versions).
1096     * <p>
1097     * The result depends on the value of the {@link #JAVA_SPECIFICATION_VERSION} constant.
1098     * </p>
1099     * <p>
1100     * The field will return {@code false} if {@link #JAVA_SPECIFICATION_VERSION} is {@code null}.
1101     * </p>
1102     * <p>
1103     * This value is initialized when the class is loaded.
1104     * </p>
1105     *
1106     * @since 3.15.0
1107     */
1108    public static final boolean IS_JAVA_22 = getJavaVersionMatches("22");
1109
1110    /**
1111     * The constant {@code true} if this is Java version 23 (also 23.x versions).
1112     * <p>
1113     * The result depends on the value of the {@link #JAVA_SPECIFICATION_VERSION} constant.
1114     * </p>
1115     * <p>
1116     * The field will return {@code false} if {@link #JAVA_SPECIFICATION_VERSION} is {@code null}.
1117     * </p>
1118     * <p>
1119     * This value is initialized when the class is loaded.
1120     * </p>
1121     *
1122     * @since 3.18.0
1123     */
1124    public static final boolean IS_JAVA_23 = getJavaVersionMatches("23");
1125
1126    /**
1127     * The constant {@code true} if this is Java version 24 (also 24.x versions).
1128     * <p>
1129     * The result depends on the value of the {@link #JAVA_SPECIFICATION_VERSION} constant.
1130     * </p>
1131     * <p>
1132     * The field will return {@code false} if {@link #JAVA_SPECIFICATION_VERSION} is {@code null}.
1133     * </p>
1134     * <p>
1135     * This value is initialized when the class is loaded.
1136     * </p>
1137     *
1138     * @since 3.18.0
1139     */
1140    public static final boolean IS_JAVA_24 = getJavaVersionMatches("24");
1141
1142    /**
1143     * The constant {@code true} if this is Java version 25 (also 25.x versions).
1144     * <p>
1145     * The result depends on the value of the {@link #JAVA_SPECIFICATION_VERSION} constant.
1146     * </p>
1147     * <p>
1148     * The field will return {@code false} if {@link #JAVA_SPECIFICATION_VERSION} is {@code null}.
1149     * </p>
1150     * <p>
1151     * This value is initialized when the class is loaded.
1152     * </p>
1153     *
1154     * @since 3.20.0
1155     */
1156    public static final boolean IS_JAVA_25 = getJavaVersionMatches("25");
1157
1158    /**
1159     * The constant {@code true} if this is Java version 26 (also 26.x versions).
1160     * <p>
1161     * The result depends on the value of the {@link #JAVA_SPECIFICATION_VERSION} constant.
1162     * </p>
1163     * <p>
1164     * The field will return {@code false} if {@link #JAVA_SPECIFICATION_VERSION} is {@code null}.
1165     * </p>
1166     * <p>
1167     * This value is initialized when the class is loaded.
1168     * </p>
1169     *
1170     * @since 3.20.0
1171     */
1172    public static final boolean IS_JAVA_26 = getJavaVersionMatches("26");
1173
1174    // Operating system checks
1175    // -----------------------------------------------------------------------
1176    // These MUST be declared after those above as they depend on the
1177    // values being set up
1178    // Please advise dev@commons.apache.org if you want another added
1179    // or a mistake corrected
1180
1181    /**
1182     * The constant {@code true} if this is AIX.
1183     * <p>
1184     * The result depends on the value of the {@link #OS_NAME} constant.
1185     * </p>
1186     * <p>
1187     * The field will return {@code false} if {@link #OS_NAME} is {@code null}.
1188     * </p>
1189     * <p>
1190     * This value is initialized when the class is loaded.
1191     * </p>
1192     *
1193     * @since 2.0
1194     */
1195    public static final boolean IS_OS_AIX = getOsNameMatches("AIX");
1196
1197    /**
1198     * The constant {@code true} if this is Android.
1199     *
1200     * <p>
1201     * See https://developer.android.com/reference/java/lang/System#getProperties().
1202     * </p>
1203     * <p>
1204     * This value is initialized when the class is loaded.
1205     * </p>
1206     *
1207     * @since 3.15.0
1208     */
1209    public static final boolean IS_OS_ANDROID = Strings.CS.contains(SystemProperties.getJavaVendor(), "Android");
1210
1211    /**
1212     * The constant {@code true} if this is HP-UX.
1213     * <p>
1214     * The result depends on the value of the {@link #OS_NAME} constant.
1215     * </p>
1216     * <p>
1217     * The field will return {@code false} if {@link #OS_NAME} is {@code null}.
1218     * </p>
1219     * <p>
1220     * This value is initialized when the class is loaded.
1221     * </p>
1222     *
1223     * @since 2.0
1224     */
1225    public static final boolean IS_OS_HP_UX = getOsNameMatches("HP-UX");
1226
1227    /**
1228     * The constant {@code true} if this is IBM OS/400.
1229     * <p>
1230     * The result depends on the value of the {@link #OS_NAME} constant.
1231     * </p>
1232     * <p>
1233     * The field will return {@code false} if {@link #OS_NAME} is {@code null}.
1234     * </p>
1235     * <p>
1236     * This value is initialized when the class is loaded.
1237     * </p>
1238     *
1239     * @since 3.3
1240     */
1241    public static final boolean IS_OS_400 = getOsNameMatches("OS/400");
1242
1243    /**
1244     * The constant {@code true} if this is Irix.
1245     * <p>
1246     * The result depends on the value of the {@link #OS_NAME} constant.
1247     * </p>
1248     * <p>
1249     * The field will return {@code false} if {@link #OS_NAME} is {@code null}.
1250     * </p>
1251     * <p>
1252     * This value is initialized when the class is loaded.
1253     * </p>
1254     *
1255     * @since 2.0
1256     */
1257    public static final boolean IS_OS_IRIX = getOsNameMatches("Irix");
1258
1259    /**
1260     * The constant {@code true} if this is Linux.
1261     * <p>
1262     * The result depends on the value of the {@link #OS_NAME} constant.
1263     * </p>
1264     * <p>
1265     * The field will return {@code false} if {@link #OS_NAME} is {@code null}.
1266     * </p>
1267     * <p>
1268     * This value is initialized when the class is loaded.
1269     * </p>
1270     *
1271     * @since 2.0
1272     */
1273    public static final boolean IS_OS_LINUX = getOsNameMatches("Linux");
1274
1275    /**
1276     * The constant {@code true} if this is Mac.
1277     * <p>
1278     * The result depends on the value of the {@link #OS_NAME} constant.
1279     * </p>
1280     * <p>
1281     * The field will return {@code false} if {@link #OS_NAME} is {@code null}.
1282     * </p>
1283     * <p>
1284     * This value is initialized when the class is loaded.
1285     * </p>
1286     *
1287     * @since 2.0
1288     */
1289    public static final boolean IS_OS_MAC = getOsNameMatches("Mac");
1290
1291    /**
1292     * The constant {@code true} if this is Mac.
1293     * <p>
1294     * The result depends on the value of the {@link #OS_NAME} constant.
1295     * </p>
1296     * <p>
1297     * The field will return {@code false} if {@link #OS_NAME} is {@code null}.
1298     * </p>
1299     * <p>
1300     * This value is initialized when the class is loaded.
1301     * </p>
1302     *
1303     * @since 2.0
1304     */
1305    public static final boolean IS_OS_MAC_OSX = getOsNameMatches("Mac OS X");
1306
1307    /**
1308     * The constant {@code true} if this is macOS X Cheetah.
1309     * <p>
1310     * The value depends on the value of the {@link #OS_NAME} and {@link #OS_VERSION} constants.
1311     * </p>
1312     * <p>
1313     * The value is {@code false} if {@link #OS_NAME} or {@link #OS_VERSION} is {@code null}.
1314     * </p>
1315     * <p>
1316     * This value is initialized when the class is loaded.
1317     * </p>
1318     *
1319     * @since 3.4
1320     */
1321    public static final boolean IS_OS_MAC_OSX_CHEETAH = getOsMatches("Mac OS X", "10.0");
1322
1323    /**
1324     * The constant {@code true} if this is macOS X Puma.
1325     * <p>
1326     * The value depends on the value of the {@link #OS_NAME} and {@link #OS_VERSION} constants.
1327     * </p>
1328     * <p>
1329     * The value is {@code false} if {@link #OS_NAME} or {@link #OS_VERSION} is {@code null}.
1330     * </p>
1331     * <p>
1332     * This value is initialized when the class is loaded.
1333     * </p>
1334     *
1335     * @since 3.4
1336     */
1337    public static final boolean IS_OS_MAC_OSX_PUMA = getOsMatches("Mac OS X", "10.1");
1338
1339    /**
1340     * The constant {@code true} if this is macOS X Jaguar.
1341     * <p>
1342     * The value depends on the value of the {@link #OS_NAME} and {@link #OS_VERSION} constants.
1343     * </p>
1344     * <p>
1345     * The value is {@code false} if {@link #OS_NAME} or {@link #OS_VERSION} is {@code null}.
1346     * </p>
1347     * <p>
1348     * This value is initialized when the class is loaded.
1349     * </p>
1350     *
1351     * @since 3.4
1352     */
1353    public static final boolean IS_OS_MAC_OSX_JAGUAR = getOsMatches("Mac OS X", "10.2");
1354
1355    /**
1356     * The constant {@code true} if this is macOS X Panther.
1357     * <p>
1358     * The value depends on the value of the {@link #OS_NAME} and {@link #OS_VERSION} constants.
1359     * </p>
1360     * <p>
1361     * The value is {@code false} if {@link #OS_NAME} or {@link #OS_VERSION} is {@code null}.
1362     * </p>
1363     * <p>
1364     * This value is initialized when the class is loaded.
1365     * </p>
1366     *
1367     * @since 3.4
1368     */
1369    public static final boolean IS_OS_MAC_OSX_PANTHER = getOsMatches("Mac OS X", "10.3");
1370
1371    /**
1372     * The constant {@code true} if this is macOS X Tiger.
1373     * <p>
1374     * The value depends on the value of the {@link #OS_NAME} and {@link #OS_VERSION} constants.
1375     * </p>
1376     * <p>
1377     * The value is {@code false} if {@link #OS_NAME} or {@link #OS_VERSION} is {@code null}.
1378     * </p>
1379     * <p>
1380     * This value is initialized when the class is loaded.
1381     * </p>
1382     *
1383     * @since 3.4
1384     */
1385    public static final boolean IS_OS_MAC_OSX_TIGER = getOsMatches("Mac OS X", "10.4");
1386
1387    /**
1388     * The constant {@code true} if this is macOS X Leopard.
1389     * <p>
1390     * The value depends on the value of the {@link #OS_NAME} and {@link #OS_VERSION} constants.
1391     * </p>
1392     * <p>
1393     * The value is {@code false} if {@link #OS_NAME} or {@link #OS_VERSION} is {@code null}.
1394     * </p>
1395     * <p>
1396     * This value is initialized when the class is loaded.
1397     * </p>
1398     *
1399     * @since 3.4
1400     */
1401    public static final boolean IS_OS_MAC_OSX_LEOPARD = getOsMatches("Mac OS X", "10.5");
1402
1403    /**
1404     * The constant {@code true} if this is macOS X Snow Leopard.
1405     * <p>
1406     * The value depends on the value of the {@link #OS_NAME} and {@link #OS_VERSION} constants.
1407     * </p>
1408     * <p>
1409     * The value is {@code false} if {@link #OS_NAME} or {@link #OS_VERSION} is {@code null}.
1410     * </p>
1411     * <p>
1412     * This value is initialized when the class is loaded.
1413     * </p>
1414     *
1415     * @since 3.4
1416     */
1417    public static final boolean IS_OS_MAC_OSX_SNOW_LEOPARD = getOsMatches("Mac OS X", "10.6");
1418
1419    /**
1420     * The constant {@code true} if this is macOS X Lion.
1421     * <p>
1422     * The value depends on the value of the {@link #OS_NAME} and {@link #OS_VERSION} constants.
1423     * </p>
1424     * <p>
1425     * The value is {@code false} if {@link #OS_NAME} or {@link #OS_VERSION} is {@code null}.
1426     * </p>
1427     * <p>
1428     * This value is initialized when the class is loaded.
1429     * </p>
1430     *
1431     * @since 3.4
1432     */
1433    public static final boolean IS_OS_MAC_OSX_LION = getOsMatches("Mac OS X", "10.7");
1434
1435    /**
1436     * The constant {@code true} if this is macOS X Mountain Lion.
1437     * <p>
1438     * The value depends on the value of the {@link #OS_NAME} and {@link #OS_VERSION} constants.
1439     * </p>
1440     * <p>
1441     * The value is {@code false} if {@link #OS_NAME} or {@link #OS_VERSION} is {@code null}.
1442     * </p>
1443     * <p>
1444     * This value is initialized when the class is loaded.
1445     * </p>
1446     *
1447     * @since 3.4
1448     */
1449    public static final boolean IS_OS_MAC_OSX_MOUNTAIN_LION = getOsMatches("Mac OS X", "10.8");
1450
1451    /**
1452     * The constant {@code true} if this is macOS X Mavericks.
1453     * <p>
1454     * The value depends on the value of the {@link #OS_NAME} and {@link #OS_VERSION} constants.
1455     * </p>
1456     * <p>
1457     * The value is {@code false} if {@link #OS_NAME} or {@link #OS_VERSION} is {@code null}.
1458     * </p>
1459     * <p>
1460     * This value is initialized when the class is loaded.
1461     * </p>
1462     *
1463     * @since 3.4
1464     */
1465    public static final boolean IS_OS_MAC_OSX_MAVERICKS = getOsMatches("Mac OS X", "10.9");
1466
1467    /**
1468     * The constant {@code true} if this is macOS X Yosemite.
1469     * <p>
1470     * The value depends on the value of the {@link #OS_NAME} and {@link #OS_VERSION} constants.
1471     * </p>
1472     * <p>
1473     * The value is {@code false} if {@link #OS_NAME} or {@link #OS_VERSION} is {@code null}.
1474     * </p>
1475     * <p>
1476     * This value is initialized when the class is loaded.
1477     * </p>
1478     *
1479     * @since 3.4
1480     */
1481    public static final boolean IS_OS_MAC_OSX_YOSEMITE = getOsMatches("Mac OS X", "10.10");
1482
1483    /**
1484     * The constant {@code true} if this is macOS X El Capitan.
1485     * <p>
1486     * The value depends on the value of the {@link #OS_NAME} and {@link #OS_VERSION} constants.
1487     * </p>
1488     * <p>
1489     * The value is {@code false} if {@link #OS_NAME} or {@link #OS_VERSION} is {@code null}.
1490     * </p>
1491     * <p>
1492     * This value is initialized when the class is loaded.
1493     * </p>
1494     *
1495     * @since 3.5
1496     */
1497    public static final boolean IS_OS_MAC_OSX_EL_CAPITAN = getOsMatches("Mac OS X", "10.11");
1498
1499    /**
1500     * The constant {@code true} if this is macOS X Sierra.
1501     * <p>
1502     * The value depends on the value of the {@link #OS_NAME} and {@link #OS_VERSION} constants.
1503     * </p>
1504     * <p>
1505     * The value is {@code false} if {@link #OS_NAME} or {@link #OS_VERSION} is {@code null}.
1506     * </p>
1507     * <p>
1508     * This value is initialized when the class is loaded.
1509     * </p>
1510     *
1511     * @since 3.12.0
1512     */
1513    public static final boolean IS_OS_MAC_OSX_SIERRA = getOsMatches("Mac OS X", "10.12");
1514
1515    /**
1516     * The constant {@code true} if this is macOS X High Sierra.
1517     * <p>
1518     * The value depends on the value of the {@link #OS_NAME} and {@link #OS_VERSION} constants.
1519     * </p>
1520     * <p>
1521     * The value is {@code false} if {@link #OS_NAME} or {@link #OS_VERSION} is {@code null}.
1522     * </p>
1523     * <p>
1524     * This value is initialized when the class is loaded.
1525     * </p>
1526     *
1527     * @since 3.12.0
1528     */
1529    public static final boolean IS_OS_MAC_OSX_HIGH_SIERRA = getOsMatches("Mac OS X", "10.13");
1530
1531    /**
1532     * The constant {@code true} if this is macOS X Mojave.
1533     * <p>
1534     * The value depends on the value of the {@link #OS_NAME} and {@link #OS_VERSION} constants.
1535     * </p>
1536     * <p>
1537     * The value is {@code false} if {@link #OS_NAME} or {@link #OS_VERSION} is {@code null}.
1538     * </p>
1539     * <p>
1540     * This value is initialized when the class is loaded.
1541     * </p>
1542     *
1543     * @since 3.12.0
1544     */
1545    public static final boolean IS_OS_MAC_OSX_MOJAVE = getOsMatches("Mac OS X", "10.14");
1546
1547    /**
1548     * The constant {@code true} if this is macOS X Catalina.
1549     *
1550     * <p>
1551     * The field will return {@code false} if {@code OS_NAME} is {@code null}.
1552     * </p>
1553     * <p>
1554     * This value is initialized when the class is loaded.
1555     * </p>
1556     *
1557     * @since 3.12.0
1558     */
1559    public static final boolean IS_OS_MAC_OSX_CATALINA = getOsMatches("Mac OS X", "10.15");
1560
1561    /**
1562     * The constant {@code true} if this is macOS X Big Sur.
1563     * <p>
1564     * The value depends on the value of the {@link #OS_NAME} and {@link #OS_VERSION} constants.
1565     * </p>
1566     * <p>
1567     * The value is {@code false} if {@link #OS_NAME} or {@link #OS_VERSION} is {@code null}.
1568     * </p>
1569     * <p>
1570     * This value is initialized when the class is loaded.
1571     * </p>
1572     *
1573     * @since 3.12.0
1574     */
1575    public static final boolean IS_OS_MAC_OSX_BIG_SUR = getOsMatches("Mac OS X", "11");
1576
1577    /**
1578     * The constant {@code true} if this is macOS X Monterey.
1579     * <p>
1580     * The value depends on the value of the {@link #OS_NAME} and {@link #OS_VERSION} constants.
1581     * </p>
1582     * <p>
1583     * The value is {@code false} if {@link #OS_NAME} or {@link #OS_VERSION} is {@code null}.
1584     * </p>
1585     * <p>
1586     * This value is initialized when the class is loaded.
1587     * </p>
1588     *
1589     * @since 3.13.0
1590     */
1591    public static final boolean IS_OS_MAC_OSX_MONTEREY = getOsMatches("Mac OS X", "12");
1592
1593    /**
1594     * The constant {@code true} if this is macOS X Ventura.
1595     * <p>
1596     * The value depends on the value of the {@link #OS_NAME} and {@link #OS_VERSION} constants.
1597     * </p>
1598     * <p>
1599     * The value is {@code false} if {@link #OS_NAME} or {@link #OS_VERSION} is {@code null}.
1600     * </p>
1601     * <p>
1602     * This value is initialized when the class is loaded.
1603     * </p>
1604     *
1605     * @since 3.13.0
1606     */
1607    public static final boolean IS_OS_MAC_OSX_VENTURA = getOsMatches("Mac OS X", "13");
1608
1609    /**
1610     * The constant {@code true} if this is macOS X Sonoma.
1611     * <p>
1612     * The value depends on the value of the {@link #OS_NAME} and {@link #OS_VERSION} constants.
1613     * </p>
1614     * <p>
1615     * The value is {@code false} if {@link #OS_NAME} or {@link #OS_VERSION} is {@code null}.
1616     * </p>
1617     * <p>
1618     * This value is initialized when the class is loaded.
1619     * </p>
1620     *
1621     * @since 3.15.0
1622     */
1623    public static final boolean IS_OS_MAC_OSX_SONOMA = getOsMatches("Mac OS X", "14");
1624
1625    /**
1626     * The constant {@code true} if this is macOS X Sequoia.
1627     * <p>
1628     * The value depends on the value of the {@link #OS_NAME} and {@link #OS_VERSION} constants.
1629     * </p>
1630     * <p>
1631     * The value is {@code false} if {@link #OS_NAME} or {@link #OS_VERSION} is {@code null}.
1632     * </p>
1633     * <p>
1634     * This value is initialized when the class is loaded.
1635     * </p>
1636     *
1637     * @since 3.18.0
1638     */
1639    public static final boolean IS_OS_MAC_OSX_SEQUOIA = getOsMatches("Mac OS X", "15");
1640
1641    /**
1642     * The constant {@code true} if this is FreeBSD.
1643     * <p>
1644     * The result depends on the value of the {@link #OS_NAME} constant.
1645     * </p>
1646     * <p>
1647     * The field will return {@code false} if {@link #OS_NAME} is {@code null}.
1648     * </p>
1649     * <p>
1650     * This value is initialized when the class is loaded.
1651     * </p>
1652     *
1653     * @since 3.1
1654     */
1655    public static final boolean IS_OS_FREE_BSD = getOsNameMatches("FreeBSD");
1656
1657    /**
1658     * The constant {@code true} if this is OpenBSD.
1659     * <p>
1660     * The result depends on the value of the {@link #OS_NAME} constant.
1661     * </p>
1662     * <p>
1663     * The field will return {@code false} if {@link #OS_NAME} is {@code null}.
1664     * </p>
1665     * <p>
1666     * This value is initialized when the class is loaded.
1667     * </p>
1668     *
1669     * @since 3.1
1670     */
1671    public static final boolean IS_OS_OPEN_BSD = getOsNameMatches("OpenBSD");
1672
1673    /**
1674     * The constant {@code true} if this is NetBSD.
1675     * <p>
1676     * The result depends on the value of the {@link #OS_NAME} constant.
1677     * </p>
1678     * <p>
1679     * The field will return {@code false} if {@link #OS_NAME} is {@code null}.
1680     * </p>
1681     * <p>
1682     * This value is initialized when the class is loaded.
1683     * </p>
1684     *
1685     * @since 3.1
1686     */
1687    public static final boolean IS_OS_NET_BSD = getOsNameMatches("NetBSD");
1688
1689    /**
1690     * The constant {@code true} if this is Netware.
1691     * <p>
1692     * The result depends on the value of the {@link #OS_NAME} constant.
1693     * </p>
1694     * <p>
1695     * The field will return {@code false} if {@link #OS_NAME} is {@code null}.
1696     * </p>
1697     * <p>
1698     * This value is initialized when the class is loaded.
1699     * </p>
1700     *
1701     * @since 3.19.0
1702     */
1703    public static final boolean IS_OS_NETWARE = getOsNameMatches("Netware");
1704
1705    /**
1706     * The constant {@code true} if this is OS/2.
1707     * <p>
1708     * The result depends on the value of the {@link #OS_NAME} constant.
1709     * </p>
1710     * <p>
1711     * The field will return {@code false} if {@link #OS_NAME} is {@code null}.
1712     * </p>
1713     * <p>
1714     * This value is initialized when the class is loaded.
1715     * </p>
1716     *
1717     * @since 2.0
1718     */
1719    public static final boolean IS_OS_OS2 = getOsNameMatches("OS/2");
1720
1721    /**
1722     * The constant {@code true} if this is Solaris.
1723     * <p>
1724     * The result depends on the value of the {@link #OS_NAME} constant.
1725     * </p>
1726     * <p>
1727     * The field will return {@code false} if {@link #OS_NAME} is {@code null}.
1728     * </p>
1729     * <p>
1730     * This value is initialized when the class is loaded.
1731     * </p>
1732     *
1733     * @since 2.0
1734     */
1735    public static final boolean IS_OS_SOLARIS = getOsNameMatches("Solaris");
1736
1737    /**
1738     * The constant {@code true} if this is SunOS.
1739     * <p>
1740     * The result depends on the value of the {@link #OS_NAME} constant.
1741     * </p>
1742     * <p>
1743     * The field will return {@code false} if {@link #OS_NAME} is {@code null}.
1744     * </p>
1745     * <p>
1746     * This value is initialized when the class is loaded.
1747     * </p>
1748     *
1749     * @since 2.0
1750     */
1751    public static final boolean IS_OS_SUN_OS = getOsNameMatches("SunOS");
1752
1753    /**
1754     * The constant {@code true} if this is a Unix like system, as in any of AIX, HP-UX, Irix, Linux, MacOSX, Solaris or SUN OS.
1755     *
1756     * <p>
1757     * The field will return {@code false} if {@code OS_NAME} is {@code null}.
1758     * </p>
1759     * <p>
1760     * This value is initialized when the class is loaded.
1761     * </p>
1762     *
1763     * @since 2.1
1764     */
1765    public static final boolean IS_OS_UNIX = IS_OS_AIX || IS_OS_HP_UX || IS_OS_IRIX || IS_OS_LINUX || IS_OS_MAC_OSX || IS_OS_SOLARIS || IS_OS_SUN_OS
1766            || IS_OS_FREE_BSD || IS_OS_OPEN_BSD || IS_OS_NET_BSD;
1767
1768    /**
1769     * The constant {@code true} if this is Windows.
1770     * <p>
1771     * The result depends on the value of the {@link #OS_NAME} constant.
1772     * </p>
1773     * <p>
1774     * The field will return {@code false} if {@link #OS_NAME} is {@code null}.
1775     * </p>
1776     * <p>
1777     * This value is initialized when the class is loaded.
1778     * </p>
1779     *
1780     * @since 2.0
1781     */
1782    public static final boolean IS_OS_WINDOWS = getOsNameMatches(OS_NAME_WINDOWS_PREFIX);
1783
1784    /**
1785     * The constant {@code true} if this is Windows 2000.
1786     * <p>
1787     * The result depends on the value of the {@link #OS_NAME} constant.
1788     * </p>
1789     * <p>
1790     * The field will return {@code false} if {@link #OS_NAME} is {@code null}.
1791     * </p>
1792     * <p>
1793     * This value is initialized when the class is loaded.
1794     * </p>
1795     *
1796     * @since 2.0
1797     */
1798    public static final boolean IS_OS_WINDOWS_2000 = getOsNameMatches(OS_NAME_WINDOWS_PREFIX + " 2000");
1799
1800    /**
1801     * The constant {@code true} if this is Windows 2003.
1802     * <p>
1803     * The result depends on the value of the {@link #OS_NAME} constant.
1804     * </p>
1805     * <p>
1806     * The field will return {@code false} if {@link #OS_NAME} is {@code null}.
1807     * </p>
1808     * <p>
1809     * This value is initialized when the class is loaded.
1810     * </p>
1811     *
1812     * @since 3.1
1813     */
1814    public static final boolean IS_OS_WINDOWS_2003 = getOsNameMatches(OS_NAME_WINDOWS_PREFIX + " 2003");
1815
1816    /**
1817     * The constant {@code true} if this is Windows Server 2008.
1818     * <p>
1819     * The result depends on the value of the {@link #OS_NAME} constant.
1820     * </p>
1821     * <p>
1822     * The field will return {@code false} if {@link #OS_NAME} is {@code null}.
1823     * </p>
1824     * <p>
1825     * This value is initialized when the class is loaded.
1826     * </p>
1827     *
1828     * @since 3.1
1829     */
1830    public static final boolean IS_OS_WINDOWS_2008 = getOsNameMatches(OS_NAME_WINDOWS_PREFIX + " Server 2008");
1831
1832    /**
1833     * The constant {@code true} if this is Windows Server 2012.
1834     * <p>
1835     * The result depends on the value of the {@link #OS_NAME} constant.
1836     * </p>
1837     * <p>
1838     * The field will return {@code false} if {@link #OS_NAME} is {@code null}.
1839     * </p>
1840     * <p>
1841     * This value is initialized when the class is loaded.
1842     * </p>
1843     *
1844     * @since 3.4
1845     */
1846    public static final boolean IS_OS_WINDOWS_2012 = getOsNameMatches(OS_NAME_WINDOWS_PREFIX + " Server 2012");
1847
1848    /**
1849     * The constant {@code true} if this is Windows 95.
1850     * <p>
1851     * The result depends on the value of the {@link #OS_NAME} constant.
1852     * </p>
1853     * <p>
1854     * The field will return {@code false} if {@link #OS_NAME} is {@code null}.
1855     * </p>
1856     * <p>
1857     * This value is initialized when the class is loaded.
1858     * </p>
1859     *
1860     * @since 2.0
1861     */
1862    public static final boolean IS_OS_WINDOWS_95 = getOsNameMatches(OS_NAME_WINDOWS_PREFIX + " 95");
1863
1864    /**
1865     * The constant {@code true} if this is Windows 98.
1866     * <p>
1867     * The result depends on the value of the {@link #OS_NAME} constant.
1868     * </p>
1869     * <p>
1870     * The field will return {@code false} if {@link #OS_NAME} is {@code null}.
1871     * </p>
1872     * <p>
1873     * This value is initialized when the class is loaded.
1874     * </p>
1875     *
1876     * @since 2.0
1877     */
1878    public static final boolean IS_OS_WINDOWS_98 = getOsNameMatches(OS_NAME_WINDOWS_PREFIX + " 98");
1879
1880    /**
1881     * The constant {@code true} if this is Windows ME.
1882     * <p>
1883     * The result depends on the value of the {@link #OS_NAME} constant.
1884     * </p>
1885     * <p>
1886     * The field will return {@code false} if {@link #OS_NAME} is {@code null}.
1887     * </p>
1888     * <p>
1889     * This value is initialized when the class is loaded.
1890     * </p>
1891     *
1892     * @since 2.0
1893     */
1894    public static final boolean IS_OS_WINDOWS_ME = getOsNameMatches(OS_NAME_WINDOWS_PREFIX + " Me");
1895
1896    /**
1897     * The constant {@code true} if this is Windows NT.
1898     * <p>
1899     * The result depends on the value of the {@link #OS_NAME} constant.
1900     * </p>
1901     * <p>
1902     * The field will return {@code false} if {@link #OS_NAME} is {@code null}.
1903     * </p>
1904     * <p>
1905     * This value is initialized when the class is loaded.
1906     * </p>
1907     *
1908     * @since 2.0
1909     */
1910    public static final boolean IS_OS_WINDOWS_NT = getOsNameMatches(OS_NAME_WINDOWS_PREFIX + " NT");
1911
1912    /**
1913     * The constant {@code true} if this is Windows XP.
1914     * <p>
1915     * The result depends on the value of the {@link #OS_NAME} constant.
1916     * </p>
1917     * <p>
1918     * The field will return {@code false} if {@link #OS_NAME} is {@code null}.
1919     * </p>
1920     * <p>
1921     * This value is initialized when the class is loaded.
1922     * </p>
1923     *
1924     * @since 2.0
1925     */
1926    public static final boolean IS_OS_WINDOWS_XP = getOsNameMatches(OS_NAME_WINDOWS_PREFIX + " XP");
1927
1928    /**
1929     * The constant {@code true} if this is Windows Vista.
1930     * <p>
1931     * The result depends on the value of the {@link #OS_NAME} constant.
1932     * </p>
1933     * <p>
1934     * The field will return {@code false} if {@link #OS_NAME} is {@code null}.
1935     * </p>
1936     * <p>
1937     * This value is initialized when the class is loaded.
1938     * </p>
1939     *
1940     * @since 2.4
1941     */
1942    public static final boolean IS_OS_WINDOWS_VISTA = getOsNameMatches(OS_NAME_WINDOWS_PREFIX + " Vista");
1943
1944    /**
1945     * The constant {@code true} if this is Windows 7.
1946     * <p>
1947     * The result depends on the value of the {@link #OS_NAME} constant.
1948     * </p>
1949     * <p>
1950     * The field will return {@code false} if {@link #OS_NAME} is {@code null}.
1951     * </p>
1952     * <p>
1953     * This value is initialized when the class is loaded.
1954     * </p>
1955     *
1956     * @since 3.0
1957     */
1958    public static final boolean IS_OS_WINDOWS_7 = getOsNameMatches(OS_NAME_WINDOWS_PREFIX + " 7");
1959
1960    /**
1961     * The constant {@code true} if this is Windows 8.
1962     * <p>
1963     * The result depends on the value of the {@link #OS_NAME} constant.
1964     * </p>
1965     * <p>
1966     * The field will return {@code false} if {@link #OS_NAME} is {@code null}.
1967     * </p>
1968     * <p>
1969     * This value is initialized when the class is loaded.
1970     * </p>
1971     *
1972     * @since 3.2
1973     */
1974    public static final boolean IS_OS_WINDOWS_8 = getOsNameMatches(OS_NAME_WINDOWS_PREFIX + " 8");
1975
1976    /**
1977     * The constant {@code true} if this is Windows 10.
1978     * <p>
1979     * The result depends on the value of the {@link #OS_NAME} constant.
1980     * </p>
1981     * <p>
1982     * The field will return {@code false} if {@link #OS_NAME} is {@code null}.
1983     * </p>
1984     * <p>
1985     * This value is initialized when the class is loaded.
1986     * </p>
1987     *
1988     * @since 3.5
1989     */
1990    public static final boolean IS_OS_WINDOWS_10 = getOsNameMatches(OS_NAME_WINDOWS_PREFIX + " 10");
1991
1992    /**
1993     * The constant {@code true} if this is Windows 11.
1994     * <p>
1995     * The result depends on the value of the {@link #OS_NAME} constant.
1996     * </p>
1997     * <p>
1998     * The field will return {@code false} if {@link #OS_NAME} is {@code null}.
1999     * </p>
2000     * <p>
2001     * OpenJDK fixed the return value for {@code os.name} on Windows 11 to versions 8, 11, and 17:
2002     * </p>
2003     * <ul>
2004     * <li>Affects Java versions 7u321, 8u311, 11.0.13-oracle, 17.0.1: https://bugs.openjdk.org/browse/JDK-8274737</li>
2005     * <li>Fixed in OpenJDK commit https://github.com/openjdk/jdk/commit/97ea9dd2f24f9f1fb9b9345a4202a825ee28e014</li>
2006     * </ul>
2007     * <p>
2008     * This value is initialized when the class is loaded.
2009     * </p>
2010     *
2011     * @since 3.13.0
2012     */
2013    public static final boolean IS_OS_WINDOWS_11 = getOsNameMatches(OS_NAME_WINDOWS_PREFIX + " 11");
2014
2015    /**
2016     * The constant {@code true} if this is z/OS.
2017     * <p>
2018     * The result depends on the value of the {@link #OS_NAME} constant.
2019     * </p>
2020     * <p>
2021     * The field will return {@code false} if {@link #OS_NAME} is {@code null}.
2022     * </p>
2023     * <p>
2024     * This value is initialized when the class is loaded.
2025     * </p>
2026     *
2027     * @since 3.5
2028     */
2029    // Values on a z/OS system I tested (Gary Gregory - 2016-03-12)
2030    // os.arch = s390x
2031    // os.encoding = ISO8859_1
2032    // os.name = z/OS
2033    // os.version = 02.02.00
2034    public static final boolean IS_OS_ZOS = getOsNameMatches("z/OS");
2035
2036    /**
2037     * The System property key for the user home directory.
2038     */
2039    public static final String USER_HOME_KEY = "user.home";
2040
2041    /**
2042     * The System property key for the user name.
2043     *
2044     * @deprecated Use {@link SystemProperties#USER_NAME}.
2045     */
2046    @Deprecated
2047    public static final String USER_NAME_KEY = "user.name";
2048
2049    /**
2050     * The System property key for the user directory.
2051     *
2052     * @deprecated Use {@link SystemProperties#USER_DIR}.
2053     */
2054    @Deprecated
2055    public static final String USER_DIR_KEY = "user.dir";
2056
2057    /**
2058     * The System property key for the Java IO temporary directory.
2059     *
2060     * @deprecated Use {@link SystemProperties#JAVA_IO_TMPDIR}.
2061     */
2062    @Deprecated
2063    public static final String JAVA_IO_TMPDIR_KEY = "java.io.tmpdir";
2064
2065    /**
2066     * The System property key for the Java home directory.
2067     *
2068     * @deprecated Use {@link SystemProperties#JAVA_HOME}.
2069     */
2070    @Deprecated
2071    public static final String JAVA_HOME_KEY = "java.home";
2072
2073    /**
2074     * A constant for the System Property {@code awt.toolkit}.
2075     *
2076     * <p>
2077     * Holds a class name, on Windows XP this is {@code sun.awt.windows.WToolkit}.
2078     * </p>
2079     * <p>
2080     * <strong>On platforms without a GUI, this value is {@code null}.</strong>
2081     * </p>
2082     * <p>
2083     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist.
2084     * </p>
2085     * <p>
2086     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is
2087     * called after this class is loaded, the value will be out of sync with that System property.
2088     * </p>
2089     *
2090     * @since 2.1
2091     * @see SystemProperties#getAwtToolkit()
2092     * @deprecated Deprecated without replacement.
2093     */
2094    @Deprecated
2095    public static final String AWT_TOOLKIT = SystemProperties.getAwtToolkit();
2096
2097    /**
2098     * Gets an environment variable, defaulting to {@code defaultValue} if the variable cannot be read.
2099     *
2100     * <p>
2101     * If a {@link SecurityException} is caught, the return value is {@code defaultValue} and a message is written to {@code System.err}.
2102     * </p>
2103     *
2104     * @param name         the environment variable name.
2105     * @param defaultValue the default value.
2106     * @return the environment variable value or {@code defaultValue} if a security problem occurs.
2107     * @since 3.8
2108     */
2109    public static String getEnvironmentVariable(final String name, final String defaultValue) {
2110        try {
2111            final String value = System.getenv(name);
2112            return value == null ? defaultValue : value;
2113        } catch (final SecurityException ex) {
2114            // we are not allowed to look at this property
2115            // System.err.println("Caught a SecurityException reading the environment variable '" + name + "'.");
2116            return defaultValue;
2117        }
2118    }
2119
2120    /**
2121     * Gets the host name from an environment variable ({@code COMPUTERNAME} on Windows, {@code HOSTNAME} elsewhere).
2122     *
2123     * <p>
2124     * If you want to know what the network stack says is the host name, you should use {@code InetAddress.getLocalHost().getHostName()}.
2125     * </p>
2126     *
2127     * @return the host name. Will be {@code null} if the environment variable is not defined.
2128     * @since 3.6
2129     */
2130    public static String getHostName() {
2131        return IS_OS_WINDOWS ? System.getenv("COMPUTERNAME") : System.getenv("HOSTNAME");
2132    }
2133
2134    /**
2135     * Gets the current Java home directory as a {@link File}.
2136     *
2137     * @return a directory.
2138     * @throws SecurityException if a security manager exists and its {@code checkPropertyAccess} method doesn't allow access to the specified system property.
2139     * @see SystemProperties#getJavaHome()
2140     * @since 2.1
2141     */
2142    public static File getJavaHome() {
2143        return new File(SystemProperties.getJavaHome());
2144    }
2145
2146    /**
2147     * Gets the current Java home directory as a {@link File}.
2148     *
2149     * @return a directory.
2150     * @throws SecurityException if a security manager exists and its {@code checkPropertyAccess} method doesn't allow access to the specified system property.
2151     * @see SystemProperties#getJavaHome()
2152     * @since 3.18.0
2153     */
2154    public static Path getJavaHomePath() {
2155        return Paths.get(SystemProperties.getJavaHome());
2156    }
2157
2158    /**
2159     * Gets the current Java IO temporary directory as a {@link File}.
2160     *
2161     * @return a directory.
2162     * @throws SecurityException if a security manager exists and its {@code checkPropertyAccess} method doesn't allow access to the specified system property.
2163     * @see SystemProperties#getJavaIoTmpdir()
2164     * @since 2.1
2165     */
2166    public static File getJavaIoTmpDir() {
2167        return new File(SystemProperties.getJavaIoTmpdir());
2168    }
2169
2170    /**
2171     * Gets the current Java IO temporary directory as a {@link Path}.
2172     *
2173     * @return a directory.
2174     * @throws SecurityException if a security manager exists and its {@code checkPropertyAccess} method doesn't allow access to the specified system property.
2175     * @see SystemProperties#getJavaIoTmpdir()
2176     * @since 3.18.0
2177     */
2178    public static Path getJavaIoTmpDirPath() {
2179        return Paths.get(SystemProperties.getJavaIoTmpdir());
2180    }
2181
2182    /**
2183     * Tests if the Java version matches the version we are running.
2184     * <p>
2185     * The result depends on the value of the {@link #JAVA_SPECIFICATION_VERSION} constant.
2186     * </p>
2187     *
2188     * @param versionPrefix the prefix for the Java version.
2189     * @return true if matches, or false if not or can't determine.
2190     */
2191    private static boolean getJavaVersionMatches(final String versionPrefix) {
2192        return isJavaVersionMatch(JAVA_SPECIFICATION_VERSION, versionPrefix);
2193    }
2194
2195    /**
2196     * Tests if the operating system matches the given name prefix and version prefix.
2197     * <p>
2198     * The result depends on the value of the {@link #OS_NAME} and {@link #OS_VERSION} constants.
2199     * </p>
2200     * <p>
2201     * The method returns {@code false} if {@link #OS_NAME} or {@link #OS_VERSION} is {@code null}.
2202     * </p>
2203     *
2204     * @param osNamePrefix    the prefix for the OS name.
2205     * @param osVersionPrefix the prefix for the version.
2206     * @return true if matches, or false if not or can't determine.
2207     */
2208    private static boolean getOsMatches(final String osNamePrefix, final String osVersionPrefix) {
2209        return isOsMatch(OS_NAME, OS_VERSION, osNamePrefix, osVersionPrefix);
2210    }
2211
2212    /**
2213     * Tests if the operating system matches the given string with a case-insensitive comparison.
2214     * <p>
2215     * The result depends on the value of the {@link #OS_NAME} constant.
2216     * </p>
2217     * <p>
2218     * The method returns {@code false} if {@link #OS_NAME} is {@code null}.
2219     * </p>
2220     *
2221     * @param osNamePrefix the prefix for the OS name.
2222     * @return true if matches, or false if not or can't determine.
2223     */
2224    private static boolean getOsNameMatches(final String osNamePrefix) {
2225        return isOsNameMatch(OS_NAME, osNamePrefix);
2226    }
2227
2228    /**
2229     * Gets the current user directory as a {@link File}.
2230     * <p>
2231     * The result is based on the system property {@value SystemProperties#USER_DIR}.
2232     * </p>
2233     *
2234     * @return a directory.
2235     * @throws SecurityException if a security manager exists and its {@code checkPropertyAccess} method doesn't allow access to the specified system property.
2236     * @see SystemProperties#getUserDir()
2237     * @since 2.1
2238     */
2239    public static File getUserDir() {
2240        return new File(SystemProperties.getUserDir());
2241    }
2242
2243    /**
2244     * Gets the current user directory as a {@link Path}.
2245     * <p>
2246     * The result is based on the system property {@value SystemProperties#USER_DIR}.
2247     * </p>
2248     *
2249     * @return a directory.
2250     * @throws SecurityException if a security manager exists and its {@code checkPropertyAccess} method doesn't allow access to the specified system property.
2251     * @see SystemProperties#getUserDir()
2252     * @since 3.18.0
2253     */
2254    public static Path getUserDirPath() {
2255        return Paths.get(SystemProperties.getUserDir());
2256    }
2257
2258    /**
2259     * Gets the current user home directory as a {@link File}.
2260     * <p>
2261     * The result is based on the system property {@value SystemProperties#USER_HOME}.
2262     * </p>
2263     *
2264     * @return a directory.
2265     * @throws SecurityException if a security manager exists and its {@code checkPropertyAccess} method doesn't allow access to the specified system property.
2266     * @see SystemProperties#getUserHome()
2267     * @since 2.1
2268     */
2269    public static File getUserHome() {
2270        return new File(SystemProperties.getUserHome());
2271    }
2272
2273    /**
2274     * Gets the current user home directory as a {@link Path}.
2275     * <p>
2276     * The result is based on the system property {@value SystemProperties#USER_HOME}.
2277     * </p>
2278     *
2279     * @return a directory.
2280     * @throws SecurityException if a security manager exists and its {@code checkPropertyAccess} method doesn't allow access to the specified system property.
2281     * @see SystemProperties#getUserHome()
2282     * @since 3.18.0
2283     */
2284    public static Path getUserHomePath() {
2285        return Paths.get(SystemProperties.getUserHome());
2286    }
2287
2288    /**
2289     * Gets the current user name.
2290     * <p>
2291     * The result is based on the system property {@value SystemProperties#USER_NAME}.
2292     * </p>
2293     *
2294     * @return a name.
2295     * @throws SecurityException if a security manager exists and its {@code checkPropertyAccess} method doesn't allow access to the specified system property.
2296     * @see SystemProperties#getUserName()
2297     * @since 3.10
2298     * @deprecated Use {@link SystemProperties#getUserName()}.
2299     */
2300    @Deprecated
2301    public static String getUserName() {
2302        return SystemProperties.getUserName();
2303    }
2304
2305    /**
2306     * Gets the user name.
2307     * <p>
2308     * The result is based on the system property {@value SystemProperties#USER_NAME}.
2309     * </p>
2310     *
2311     * @param defaultValue A default value.
2312     * @return a name.
2313     * @throws SecurityException if a security manager exists and its {@code checkPropertyAccess} method doesn't allow access to the specified system property.
2314     * @see SystemProperties#getUserName()
2315     * @since 3.10
2316     * @deprecated Use {@link SystemProperties#getUserName(String)}.
2317     */
2318    @Deprecated
2319    public static String getUserName(final String defaultValue) {
2320        return SystemProperties.getUserName(defaultValue);
2321    }
2322
2323    /**
2324     * Tests whether the {@link #JAVA_AWT_HEADLESS} value is {@code true}.
2325     * <p>
2326     * The result is based on the system property {@value SystemProperties#JAVA_AWT_HEADLESS}.
2327     * </p>
2328     *
2329     * @return {@code true} if {@code JAVA_AWT_HEADLESS} is {@code "true"}, {@code false} otherwise.
2330     * @see #JAVA_AWT_HEADLESS
2331     * @since 2.1
2332     * @since Java 1.4
2333     * @deprecated Deprecated without replacement.
2334     */
2335    @Deprecated
2336    public static boolean isJavaAwtHeadless() {
2337        return Boolean.TRUE.toString().equals(JAVA_AWT_HEADLESS);
2338    }
2339
2340    /**
2341     * Tests whether the Java version is at least the requested version.
2342     * <p>
2343     * The result is based on the system property saved in {@link #JAVA_SPECIFICATION_VERSION}.
2344     * </p>
2345     *
2346     * @param requiredVersion the required version, for example 1.31f.
2347     * @return {@code true} if the actual version is equal or greater than the required version.
2348     */
2349    public static boolean isJavaVersionAtLeast(final JavaVersion requiredVersion) {
2350        return JAVA_SPECIFICATION_VERSION_AS_ENUM != null && JAVA_SPECIFICATION_VERSION_AS_ENUM.atLeast(requiredVersion);
2351    }
2352
2353    /**
2354     * Tests whether the Java version is at most the requested version.
2355     * <p>
2356     * The result is based on the system property saved in {@link #JAVA_SPECIFICATION_VERSION}.
2357     * </p>
2358     *
2359     * @param requiredVersion the required version, for example 1.31f.
2360     * @return {@code true} if the actual version is equal or less than the required version.
2361     * @since 3.9
2362     */
2363    public static boolean isJavaVersionAtMost(final JavaVersion requiredVersion) {
2364        return JAVA_SPECIFICATION_VERSION_AS_ENUM != null && JAVA_SPECIFICATION_VERSION_AS_ENUM.atMost(requiredVersion);
2365    }
2366
2367    /**
2368     * Tests whether the Java version matches.
2369     *
2370     * <p>
2371     * This method is package private instead of private to support unit test invocation.
2372     * </p>
2373     *
2374     * @param version       the actual Java version.
2375     * @param versionPrefix the prefix for the expected Java version.
2376     * @return true if matches, or false if not or can't determine.
2377     */
2378    static boolean isJavaVersionMatch(final String version, final String versionPrefix) {
2379        if (version == null) {
2380            return false;
2381        }
2382        return version.startsWith(versionPrefix);
2383    }
2384
2385    /**
2386     * Tests whether the operating system matches.
2387     * <p>
2388     * This method is package private instead of private to support unit test invocation.
2389     * </p>
2390     *
2391     * @param osName          the actual OS name.
2392     * @param osVersion       the actual OS version.
2393     * @param osNamePrefix    the prefix for the expected OS name.
2394     * @param osVersionPrefix the prefix for the expected OS version.
2395     * @return true if matches, or false if not or can't determine.
2396     */
2397    static boolean isOsMatch(final String osName, final String osVersion, final String osNamePrefix, final String osVersionPrefix) {
2398        if (osName == null || osVersion == null) {
2399            return false;
2400        }
2401        return isOsNameMatch(osName, osNamePrefix) && isOsVersionMatch(osVersion, osVersionPrefix);
2402    }
2403
2404    /**
2405     * Tests whether the operating system matches with a case-insensitive comparison.
2406     * <p>
2407     * This method is package private instead of private to support unit test invocation.
2408     * </p>
2409     *
2410     * @param osName       the actual OS name.
2411     * @param osNamePrefix the prefix for the expected OS name.
2412     * @return true for a case-insensitive match, or false if not.
2413     */
2414    static boolean isOsNameMatch(final String osName, final String osNamePrefix) {
2415        if (osName == null) {
2416            return false;
2417        }
2418        return Strings.CI.startsWith(osName, osNamePrefix);
2419    }
2420
2421    /**
2422     * Tests whether the operating system version matches.
2423     * <p>
2424     * This method is package private instead of private to support unit test invocation.
2425     * </p>
2426     *
2427     * @param osVersion       the actual OS version.
2428     * @param osVersionPrefix the prefix for the expected OS version.
2429     * @return true if matches, or false if not or can't determine.
2430     */
2431    static boolean isOsVersionMatch(final String osVersion, final String osVersionPrefix) {
2432        if (StringUtils.isEmpty(osVersion)) {
2433            return false;
2434        }
2435        // Compare parts of the version string instead of using String.startsWith(String) because otherwise
2436        // osVersionPrefix 10.1 would also match osVersion 10.10
2437        final String[] versionPrefixParts = JavaVersion.split(osVersionPrefix);
2438        final String[] versionParts = JavaVersion.split(osVersion);
2439        for (int i = 0; i < Math.min(versionPrefixParts.length, versionParts.length); i++) {
2440            if (!versionPrefixParts[i].equals(versionParts[i])) {
2441                return false;
2442            }
2443        }
2444        return true;
2445    }
2446
2447    /**
2448     * SystemUtils instances shouldn't be constructed in standard programming. Instead, elements should be accessed directly, for example
2449     * {@code SystemUtils.FILE_SEPARATOR}.
2450     *
2451     * <p>
2452     * This constructor is public to permit tools that require a JavaBean instance to operate.
2453     * </p>
2454     */
2455    public SystemUtils() {
2456    }
2457
2458}