Top Description Fields Constructors Methods
org.apache.commons.lang3

public Class SystemUtils

extends Object
Class Inheritance
Imports
java.io.File, java.nio.file.Path, .Paths

Helpers for System.

If a system property cannot be read due to security restrictions, the corresponding field in this class will be set to null and a message will be written to System.err.

#ThreadSafe#

Since
1.0
See Also
SystemProperties

Field Summary

Modifier and TypeField and Description
public static final String
AWT_TOOLKIT

Deprecated Deprecated without replacement.
A constant for the System Property awt.toolkit.
public static final String
FILE_ENCODING

A constant for the System Property file.encoding.

public static final String
FILE_SEPARATOR

Deprecated Use File#separator, since it is guaranteed to be a string containing a single character and it does not require a privilege check.
A constant for the System Property file.separator.
public static final boolean
IS_JAVA_10

The constant true if this is Java version 10 (also 10.x versions).

public static final boolean
IS_JAVA_11

The constant true if this is Java version 11 (also 11.x versions).

public static final boolean
IS_JAVA_12

The constant true if this is Java version 12 (also 12.x versions).

public static final boolean
IS_JAVA_13

The constant true if this is Java version 13 (also 13.x versions).

public static final boolean
IS_JAVA_14

The constant true if this is Java version 14 (also 14.x versions).

public static final boolean
IS_JAVA_15

The constant true if this is Java version 15 (also 15.x versions).

public static final boolean
IS_JAVA_16

The constant true if this is Java version 16 (also 16.x versions).

public static final boolean
IS_JAVA_17

The constant true if this is Java version 17 (also 17.x versions).

public static final boolean
IS_JAVA_18

The constant true if this is Java version 18 (also 18.x versions).

public static final boolean
IS_JAVA_19

The constant true if this is Java version 19 (also 19.x versions).

public static final boolean
IS_JAVA_1_1

The constant true if this is Java version 1.1 (also 1.1.x versions).

public static final boolean
IS_JAVA_1_2

The constant true if this is Java version 1.2 (also 1.2.x versions).

public static final boolean
IS_JAVA_1_3

The constant true if this is Java version 1.3 (also 1.3.x versions).

public static final boolean
IS_JAVA_1_4

The constant true if this is Java version 1.4 (also 1.4.x versions).

public static final boolean
IS_JAVA_1_5

The constant true if this is Java version 1.5 (also 1.5.x versions).

public static final boolean
IS_JAVA_1_6

The constant true if this is Java version 1.6 (also 1.6.x versions).

public static final boolean
IS_JAVA_1_7

The constant true if this is Java version 1.7 (also 1.7.x versions).

public static final boolean
IS_JAVA_1_8

The constant true if this is Java version 1.8 (also 1.8.x versions).

public static final boolean
IS_JAVA_1_9

Deprecated As of release 3.5, replaced by IS_JAVA_9.
The constant true if this is Java version 1.9 (also 1.9.x versions).
public static final boolean
IS_JAVA_20

The constant true if this is Java version 20 (also 20.x versions).

public static final boolean
IS_JAVA_21

The constant true if this is Java version 21 (also 21.x versions).

public static final boolean
IS_JAVA_22

The constant true if this is Java version 22 (also 22.x versions).

public static final boolean
IS_JAVA_23

The constant true if this is Java version 23 (also 23.x versions).

public static final boolean
IS_JAVA_24

The constant true if this is Java version 24 (also 24.x versions).

public static final boolean
IS_JAVA_25

The constant true if this is Java version 25 (also 25.x versions).

public static final boolean
IS_JAVA_26

The constant true if this is Java version 26 (also 26.x versions).

public static final boolean
IS_JAVA_9

The constant true if this is Java version 9 (also 9.x versions).

public static final boolean
IS_OS_400

The constant true if this is IBM OS/400.

public static final boolean
IS_OS_AIX

The constant true if this is AIX.

public static final boolean
IS_OS_ANDROID

The constant true if this is Android.

public static final boolean
IS_OS_FREE_BSD

The constant true if this is FreeBSD.

public static final boolean
IS_OS_HP_UX

The constant true if this is HP-UX.

public static final boolean
IS_OS_IRIX

The constant true if this is Irix.

public static final boolean
IS_OS_LINUX

The constant true if this is Linux.

public static final boolean
IS_OS_MAC

The constant true if this is Mac.

public static final boolean
IS_OS_MAC_OSX

The constant true if this is Mac.

public static final boolean
IS_OS_MAC_OSX_BIG_SUR

The constant true if this is macOS X Big Sur.

public static final boolean
IS_OS_MAC_OSX_CATALINA

The constant true if this is macOS X Catalina.

public static final boolean
IS_OS_MAC_OSX_CHEETAH

The constant true if this is macOS X Cheetah.

public static final boolean
IS_OS_MAC_OSX_EL_CAPITAN

The constant true if this is macOS X El Capitan.

public static final boolean
IS_OS_MAC_OSX_HIGH_SIERRA

The constant true if this is macOS X High Sierra.

public static final boolean
IS_OS_MAC_OSX_JAGUAR

The constant true if this is macOS X Jaguar.

public static final boolean
IS_OS_MAC_OSX_LEOPARD

The constant true if this is macOS X Leopard.

public static final boolean
IS_OS_MAC_OSX_LION

The constant true if this is macOS X Lion.

public static final boolean
IS_OS_MAC_OSX_MAVERICKS

The constant true if this is macOS X Mavericks.

public static final boolean
IS_OS_MAC_OSX_MOJAVE

The constant true if this is macOS X Mojave.

public static final boolean
IS_OS_MAC_OSX_MONTEREY

The constant true if this is macOS X Monterey.

public static final boolean
IS_OS_MAC_OSX_MOUNTAIN_LION

The constant true if this is macOS X Mountain Lion.

public static final boolean
IS_OS_MAC_OSX_PANTHER

The constant true if this is macOS X Panther.

public static final boolean
IS_OS_MAC_OSX_PUMA

The constant true if this is macOS X Puma.

public static final boolean
IS_OS_MAC_OSX_SEQUOIA

The constant true if this is macOS X Sequoia.

public static final boolean
IS_OS_MAC_OSX_SIERRA

The constant true if this is macOS X Sierra.

public static final boolean
IS_OS_MAC_OSX_SNOW_LEOPARD

The constant true if this is macOS X Snow Leopard.

public static final boolean
IS_OS_MAC_OSX_SONOMA

The constant true if this is macOS X Sonoma.

public static final boolean
IS_OS_MAC_OSX_TIGER

The constant true if this is macOS X Tiger.

public static final boolean
IS_OS_MAC_OSX_VENTURA

The constant true if this is macOS X Ventura.

public static final boolean
IS_OS_MAC_OSX_YOSEMITE

The constant true if this is macOS X Yosemite.

public static final boolean
IS_OS_NET_BSD

The constant true if this is NetBSD.

public static final boolean
IS_OS_NETWARE

The constant true if this is Netware.

public static final boolean
IS_OS_OPEN_BSD

The constant true if this is OpenBSD.

public static final boolean
IS_OS_OS2

The constant true if this is OS/2.

public static final boolean
IS_OS_SOLARIS

The constant true if this is Solaris.

public static final boolean
IS_OS_SUN_OS

The constant true if this is SunOS.

public static final boolean
IS_OS_UNIX

The constant true if this is a Unix like system, as in any of AIX, HP-UX, Irix, Linux, MacOSX, Solaris or SUN OS.

public static final boolean
IS_OS_WINDOWS

The constant true if this is Windows.

public static final boolean
IS_OS_WINDOWS_10

The constant true if this is Windows 10.

public static final boolean
IS_OS_WINDOWS_11

The constant true if this is Windows 11.

public static final boolean
IS_OS_WINDOWS_2000

The constant true if this is Windows 2000.

public static final boolean
IS_OS_WINDOWS_2003

The constant true if this is Windows 2003.

public static final boolean
IS_OS_WINDOWS_2008

The constant true if this is Windows Server 2008.

public static final boolean
IS_OS_WINDOWS_2012

The constant true if this is Windows Server 2012.

public static final boolean
IS_OS_WINDOWS_7

The constant true if this is Windows 7.

public static final boolean
IS_OS_WINDOWS_8

The constant true if this is Windows 8.

public static final boolean
IS_OS_WINDOWS_95

The constant true if this is Windows 95.

public static final boolean
IS_OS_WINDOWS_98

The constant true if this is Windows 98.

public static final boolean
IS_OS_WINDOWS_ME

The constant true if this is Windows ME.

public static final boolean
IS_OS_WINDOWS_NT

The constant true if this is Windows NT.

public static final boolean
IS_OS_WINDOWS_VISTA

The constant true if this is Windows Vista.

public static final boolean
IS_OS_WINDOWS_XP

The constant true if this is Windows XP.

public static final boolean
IS_OS_ZOS

The constant true if this is z/OS.

public static final String
JAVA_AWT_FONTS

Deprecated Deprecated without replacement.
A constant for the System Property java.awt.fonts.
public static final String
JAVA_AWT_GRAPHICSENV

Deprecated Deprecated without replacement.
A constant for the System Property java.awt.graphicsenv.
public static final String
JAVA_AWT_HEADLESS

Deprecated Deprecated without replacement.
A constant for the System Property java.awt.headless.
public static final String
JAVA_AWT_PRINTERJOB

Deprecated Deprecated without replacement.
A constant for the System Property java.awt.printerjob.
public static final String
JAVA_CLASS_PATH

A constant for the System Property java.class.path.

public static final String
JAVA_CLASS_VERSION

A constant for the System Property java.class.version.

public static final String
JAVA_COMPILER

Deprecated Deprecated without replacement; see https://bugs.openjdk.org/browse/JDK-8305998
A constant for the System Property java.compiler.
public static final String
JAVA_ENDORSED_DIRS

Deprecated Deprecated without replacement.
A constant for the System Property java.endorsed.dirs.
public static final String
JAVA_EXT_DIRS

Deprecated Deprecated without replacement.
A constant for the System Property java.ext.dirs.
public static final String
JAVA_HOME

A constant for the System Property java.home.

public static final String
JAVA_HOME_KEY

Deprecated Use SystemProperties#JAVA_HOME.
The System property key for the Java home directory.
public static final String
JAVA_IO_TMPDIR

A constant for the System Property java.io.tmpdir.

public static final String
JAVA_IO_TMPDIR_KEY

The System property key for the Java IO temporary directory.
public static final String
JAVA_LIBRARY_PATH

A constant for the System Property java.library.path.

public static final String
JAVA_RUNTIME_NAME

A constant for the System Property java.runtime.name.

public static final String
JAVA_RUNTIME_VERSION

A constant for the System Property java.runtime.version.

public static final String
JAVA_SPECIFICATION_NAME

A constant for the System Property java.specification.name.

public static final String
JAVA_SPECIFICATION_VENDOR

A constant for the System Property java.specification.vendor.

public static final String
JAVA_SPECIFICATION_VERSION

A constant for the System Property java.specification.version.

private static final JavaVersion
public static final String
JAVA_UTIL_PREFS_PREFERENCES_FACTORY

A constant for the System Property java.util.prefs.PreferencesFactory.

public static final String
JAVA_VENDOR

A constant for the System Property java.vendor.

public static final String
JAVA_VENDOR_URL

A constant for the System Property java.vendor.url.

public static final String
JAVA_VERSION

A constant for the System Property java.version.

public static final String
JAVA_VM_INFO

A constant for the System Property java.vm.info.

public static final String
JAVA_VM_NAME

A constant for the System Property java.vm.name.

public static final String
JAVA_VM_SPECIFICATION_NAME

A constant for the System Property java.vm.specification.name.

public static final String
JAVA_VM_SPECIFICATION_VENDOR

A constant for the System Property java.vm.specification.vendor.

public static final String
JAVA_VM_SPECIFICATION_VERSION

A constant for the System Property java.vm.specification.version.

public static final String
JAVA_VM_VENDOR

A constant for the System Property java.vm.vendor.

public static final String
JAVA_VM_VERSION

A constant for the System Property java.vm.version.

public static final String
LINE_SEPARATOR

Deprecated Use System#lineSeparator() instead, since it does not require a privilege check.
A constant for the System Property line.separator.
public static final String
OS_ARCH

A constant for the System Property os.arch.

public static final String
OS_NAME

A constant for the System Property os.name.

private static final String
OS_NAME_WINDOWS_PREFIX

The prefix String for all Windows OS.

public static final String
OS_VERSION

A constant for the System Property os.version.

public static final String
PATH_SEPARATOR

Deprecated Use File#pathSeparator, since it is guaranteed to be a string containing a single character and it does not require a privilege check.
A constant for the System Property path.separator.
public static final String
USER_COUNTRY

A constant for the System Property user.country or user.region.

public static final String
USER_DIR

A constant for the System Property user.dir.

public static final String
USER_DIR_KEY

Deprecated Use SystemProperties#USER_DIR.
The System property key for the user directory.
public static final String
USER_HOME

A constant for the System Property user.home.

public static final String
USER_HOME_KEY

The System property key for the user home directory.

public static final String
USER_LANGUAGE

A constant for the System Property user.language.

public static final String
USER_NAME

A constant for the System Property user.name.

public static final String
USER_NAME_KEY

Deprecated Use SystemProperties#USER_NAME.
The System property key for the user name.
public static final String
USER_TIMEZONE

A constant for the System Property user.timezone.

Constructor Summary

AccessConstructor and Description
public
SystemUtils()

SystemUtils instances shouldn't be constructed in standard programming.

Method Summary

Modifier and TypeMethod and Description
public static String

Returns:

the environment variable value or defaultValue if a security problem occurs.
getEnvironmentVariable
(final String
the environment variable name.
name
,
final String
the default value.
defaultValue
)

Gets an environment variable, defaulting to defaultValue if the variable cannot be read.

public static String

Returns:

the host name. Will be null if the environment variable is not defined.
getHostName
()

Gets the host name from an environment variable (COMPUTERNAME on Windows, HOSTNAME elsewhere).

public static File

Returns:

a directory.
getJavaHome
()

Gets the current Java home directory as a File.

public static Path

Returns:

a directory.
getJavaHomePath
()

Gets the current Java home directory as a File.

public static File

Returns:

a directory.
getJavaIoTmpDir
()

Gets the current Java IO temporary directory as a File.

public static Path

Returns:

a directory.
getJavaIoTmpDirPath
()

Gets the current Java IO temporary directory as a Path.

private static boolean

Returns:

true if matches, or false if not or can't determine.
getJavaVersionMatches
(final String
the prefix for the Java version.
versionPrefix
)

Tests if the Java version matches the version we are running.

private static boolean

Returns:

true if matches, or false if not or can't determine.
getOsMatches
(final String
the prefix for the OS name.
osNamePrefix
,
final String
the prefix for the version.
osVersionPrefix
)

Tests if the operating system matches the given name prefix and version prefix.

private static boolean

Returns:

true if matches, or false if not or can't determine.
getOsNameMatches
(final String
the prefix for the OS name.
osNamePrefix
)

Tests if the operating system matches the given string with a case-insensitive comparison.

public static File

Returns:

a directory.
getUserDir
()

Gets the current user directory as a File.

public static Path

Returns:

a directory.
getUserDirPath
()

Gets the current user directory as a Path.

public static File

Returns:

a directory.
getUserHome
()

Gets the current user home directory as a File.

public static Path

Returns:

a directory.
getUserHomePath
()

Gets the current user home directory as a Path.

public static String

Returns:

a name.
getUserName
()

Gets the current user name.

public static String

Returns:

a name.
getUserName
(final String
A default value.
defaultValue
)

Gets the user name.

public static boolean

Returns:

true if JAVA_AWT_HEADLESS is "true", false otherwise.
isJavaAwtHeadless
()
Deprecated Deprecated without replacement.

Tests whether the JAVA_AWT_HEADLESS value is true.

public static boolean

Returns:

true if the actual version is equal or greater than the required version.
isJavaVersionAtLeast
(final JavaVersion
the required version, for example 1.31f.
requiredVersion
)

Tests whether the Java version is at least the requested version.

public static boolean

Returns:

true if the actual version is equal or less than the required version.
isJavaVersionAtMost
(final JavaVersion
the required version, for example 1.31f.
requiredVersion
)

Tests whether the Java version is at most the requested version.

pack-priv static boolean

Returns:

true if matches, or false if not or can't determine.
isJavaVersionMatch
(final String
the actual Java version.
version
,
final String
the prefix for the expected Java version.
versionPrefix
)

Tests whether the Java version matches.

pack-priv static boolean

Returns:

true if matches, or false if not or can't determine.
isOsMatch
(final String
the actual OS name.
osName
,
final String
the actual OS version.
osVersion
,
final String
the prefix for the expected OS name.
osNamePrefix
,
final String
the prefix for the expected OS version.
osVersionPrefix
)

Tests whether the operating system matches.

pack-priv static boolean

Returns:

true for a case-insensitive match, or false if not.
isOsNameMatch
(final String
the actual OS name.
osName
,
final String
the prefix for the expected OS name.
osNamePrefix
)

Tests whether the operating system matches with a case-insensitive comparison.

pack-priv static boolean

Returns:

true if matches, or false if not or can't determine.
isOsVersionMatch
(final String
the actual OS version.
osVersion
,
final String
the prefix for the expected OS version.
osVersionPrefix
)

Tests whether the operating system version matches.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait