Interface SystemProperties
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Code that reads system properties through a SystemProperties it is given, rather than through
System.getProperty(String), can be tested with of(Map).
Besides get(String), which reads any property, there is a typed method for each property listed in the
Java SE 25 documentation of System.getProperties(), followed by the ones the JDK supports. The properties
every Java runtime must define are returned as is, and throw NoSuchElementException if the source lacks them,
which only a fixed source can. The others are returned as an Optional, or as an empty list for paths.
Paths are returned in the default file system, as Path.of(String, String...) makes them. Path lists, such
as javaClassPath(), are split on the path separator of the same source, with empty entries skipped. A
Platform may be more appropriate for paths: its directories are in the file system
it was given, which tests can replace. get(String) still gives any value as a string.
-
Method Summary
Modifier and TypeMethodDescriptionReturns the name of the default charset.default StringReturns the file separator,"/"on Unix: thefile.separatorproperty.Returns the value of a property.Returns the class path, split on the path separator: thejava.class.pathproperty.default StringReturns the latest class file format version the Java runtime recognizes, asMAJOR.MINOR: thejava.class.versionproperty.default PathjavaHome()Returns the installation directory of Java: thejava.homeproperty.default PathReturns the default temporary file directory: thejava.io.tmpdirproperty.Returns the paths searched when loading libraries, split on the path separator: thejava.library.pathproperty.default OptionalIntReturns the maintenance version of the Java Runtime Environment specification, which is set only after a maintenance release: thejava.specification.maintenance.versionproperty.default StringReturns the name of the Java Runtime Environment specification: thejava.specification.nameproperty.default StringReturns the vendor of the Java Runtime Environment specification: thejava.specification.vendorproperty.default intReturns the version of the Java Runtime Environment specification: the feature element of the runtime version, such as21: thejava.specification.versionproperty.default StringReturns the vendor of the Java Runtime Environment: thejava.vendorproperty.default URIReturns the URL of the Java vendor: thejava.vendor.urlproperty.Returns the version of the Java vendor, which is optional: thejava.vendor.versionproperty.default Runtime.VersionReturns the version of the Java Runtime Environment: thejava.versionproperty.default LocalDateReturns the version date of the Java Runtime Environment: thejava.version.dateproperty.default StringReturns the name of the Java Virtual Machine implementation: thejava.vm.nameproperty.default StringReturns the name of the Java Virtual Machine specification: thejava.vm.specification.nameproperty.default StringReturns the vendor of the Java Virtual Machine specification: thejava.vm.specification.vendorproperty.default intReturns the version of the Java Virtual Machine specification: the feature element of the runtime version, such as21: thejava.vm.specification.versionproperty.default StringReturns the vendor of the Java Virtual Machine implementation: thejava.vm.vendorproperty.default Runtime.VersionReturns the version of the Java Virtual Machine implementation: thejava.vm.versionproperty.Returns the name of the initial (main) module, if the application was launched from a module: thejdk.module.mainproperty.Returns the main class of the initial module, if the application was launched from a module: thejdk.module.main.classproperty.Returns the application module path, split on the path separator; empty when the application does not use one: thejdk.module.pathproperty.Returns the upgrade module path, split on the path separator; empty when there is none: thejdk.module.upgrade.pathproperty.default StringReturns the line separator,"\n"on Unix: theline.separatorproperty.default CharsetReturns the character encoding derived from the host environment and the user's settings: thenative.encodingproperty.static SystemPropertiesReturns fixed system properties.default StringosArch()Returns the architecture of the operating system: theos.archproperty.default StringosName()Returns the name of the operating system: theos.nameproperty.default StringReturns the version of the operating system: theos.versionproperty.default StringReturns the path separator,":"on Unix: thepath.separatorproperty.default CharsetReturns the character encoding ofSystem.err: thestderr.encodingproperty.default CharsetReturns the character encoding ofSystem.in: thestdin.encodingproperty.default CharsetReturns the character encoding ofSystem.out: thestdout.encodingproperty.static SystemPropertiessystem()Returns the system properties of the running JVM.default PathuserDir()Returns the current working directory of the user: theuser.dirproperty.default PathuserHome()Returns the home directory of the user: theuser.homeproperty.default StringuserName()Returns the name of the user account: theuser.nameproperty.
-
Method Details
-
system
Returns the system properties of the running JVM. Each call reads the current value.- Returns:
- the JVM's system properties
-
of
Returns fixed system properties.- Parameters:
properties- the properties, by name; copied- Returns:
- system properties holding exactly
properties
-
get
Returns the value of a property.- Parameters:
name- the name of the property, such as"user.home"- Returns:
- the value, or empty if the property is not set
- Throws:
IllegalArgumentException- ifnameis empty
-
javaVersion
Returns the version of the Java Runtime Environment: thejava.versionproperty.- Returns:
- the value
- Throws:
NoSuchElementException- if the property is not setIllegalArgumentException- if the property is not a valid version
-
javaVersionDate
Returns the version date of the Java Runtime Environment: thejava.version.dateproperty.- Returns:
- the value
- Throws:
NoSuchElementException- if the property is not setDateTimeParseException- if the property is not a valid date
-
javaVendor
Returns the vendor of the Java Runtime Environment: thejava.vendorproperty.- Returns:
- the value
- Throws:
NoSuchElementException- if the property is not set
-
javaVendorUrl
Returns the URL of the Java vendor: thejava.vendor.urlproperty.- Returns:
- the value
- Throws:
NoSuchElementException- if the property is not setIllegalArgumentException- if the property is not a valid URI
-
javaVendorVersion
-
javaHome
Returns the installation directory of Java: thejava.homeproperty.The path is in the default file system, as
Path.of(String, String...)makes it. APlatformmay be more appropriate: its paths are in the file system it was given, which tests can replace.- Returns:
- the value
- Throws:
NoSuchElementException- if the property is not setInvalidPathException- if the value is not a path of the default file system
-
javaVmSpecificationVersion
default int javaVmSpecificationVersion()Returns the version of the Java Virtual Machine specification: the feature element of the runtime version, such as21: thejava.vm.specification.versionproperty.- Returns:
- the value
- Throws:
NoSuchElementException- if the property is not setNumberFormatException- if the property is not an integer
-
javaVmSpecificationVendor
Returns the vendor of the Java Virtual Machine specification: thejava.vm.specification.vendorproperty.- Returns:
- the value
- Throws:
NoSuchElementException- if the property is not set
-
javaVmSpecificationName
Returns the name of the Java Virtual Machine specification: thejava.vm.specification.nameproperty.- Returns:
- the value
- Throws:
NoSuchElementException- if the property is not set
-
javaVmVersion
Returns the version of the Java Virtual Machine implementation: thejava.vm.versionproperty.- Returns:
- the value
- Throws:
NoSuchElementException- if the property is not setIllegalArgumentException- if the property is not a valid version
-
javaVmVendor
Returns the vendor of the Java Virtual Machine implementation: thejava.vm.vendorproperty.- Returns:
- the value
- Throws:
NoSuchElementException- if the property is not set
-
javaVmName
Returns the name of the Java Virtual Machine implementation: thejava.vm.nameproperty.- Returns:
- the value
- Throws:
NoSuchElementException- if the property is not set
-
javaSpecificationVersion
default int javaSpecificationVersion()Returns the version of the Java Runtime Environment specification: the feature element of the runtime version, such as21: thejava.specification.versionproperty.- Returns:
- the value
- Throws:
NoSuchElementException- if the property is not setNumberFormatException- if the property is not an integer
-
javaSpecificationMaintenanceVersion
Returns the maintenance version of the Java Runtime Environment specification, which is set only after a maintenance release: thejava.specification.maintenance.versionproperty.- Returns:
- the value, or empty if it is not set
- Throws:
NumberFormatException- if the property is set but is not an integer
-
javaSpecificationVendor
Returns the vendor of the Java Runtime Environment specification: thejava.specification.vendorproperty.- Returns:
- the value
- Throws:
NoSuchElementException- if the property is not set
-
javaSpecificationName
Returns the name of the Java Runtime Environment specification: thejava.specification.nameproperty.- Returns:
- the value
- Throws:
NoSuchElementException- if the property is not set
-
javaClassVersion
Returns the latest class file format version the Java runtime recognizes, asMAJOR.MINOR: thejava.class.versionproperty.- Returns:
- the value
- Throws:
NoSuchElementException- if the property is not set
-
javaClassPath
Returns the class path, split on the path separator: thejava.class.pathproperty.The paths are in the default file system, as
Path.of(String, String...)makes them. APlatformmay be more appropriate: its paths are in the file system it was given, which tests can replace.- Returns:
- the value
- Throws:
NoSuchElementException- if the property or thepath.separatorproperty is not setIllegalArgumentException- if thepath.separatorproperty is emptyInvalidPathException- if an entry is not a path of the default file system
-
javaLibraryPath
Returns the paths searched when loading libraries, split on the path separator: thejava.library.pathproperty.The paths are in the default file system, as
Path.of(String, String...)makes them. APlatformmay be more appropriate: its paths are in the file system it was given, which tests can replace.- Returns:
- the value
- Throws:
NoSuchElementException- if the property or thepath.separatorproperty is not setIllegalArgumentException- if thepath.separatorproperty is emptyInvalidPathException- if an entry is not a path of the default file system
-
javaIoTmpdir
Returns the default temporary file directory: thejava.io.tmpdirproperty.The path is in the default file system, as
Path.of(String, String...)makes it. APlatformmay be more appropriate: its paths are in the file system it was given, which tests can replace.- Returns:
- the value
- Throws:
NoSuchElementException- if the property is not setInvalidPathException- if the value is not a path of the default file system
-
osName
Returns the name of the operating system: theos.nameproperty.- Returns:
- the value
- Throws:
NoSuchElementException- if the property is not set
-
osArch
Returns the architecture of the operating system: theos.archproperty.- Returns:
- the value
- Throws:
NoSuchElementException- if the property is not set
-
osVersion
Returns the version of the operating system: theos.versionproperty.- Returns:
- the value
- Throws:
NoSuchElementException- if the property is not set
-
fileSeparator
Returns the file separator,"/"on Unix: thefile.separatorproperty.- Returns:
- the value
- Throws:
NoSuchElementException- if the property is not set
-
pathSeparator
Returns the path separator,":"on Unix: thepath.separatorproperty.- Returns:
- the value
- Throws:
NoSuchElementException- if the property is not set
-
lineSeparator
Returns the line separator,"\n"on Unix: theline.separatorproperty.- Returns:
- the value
- Throws:
NoSuchElementException- if the property is not set
-
userName
Returns the name of the user account: theuser.nameproperty.- Returns:
- the value
- Throws:
NoSuchElementException- if the property is not set
-
userHome
Returns the home directory of the user: theuser.homeproperty.The path is in the default file system, as
Path.of(String, String...)makes it. APlatformmay be more appropriate: thehomeof its directories is in the file system it was given, which tests can replace.- Returns:
- the value
- Throws:
NoSuchElementException- if the property is not setInvalidPathException- if the value is not a path of the default file system
-
userDir
Returns the current working directory of the user: theuser.dirproperty.The path is in the default file system, as
Path.of(String, String...)makes it. APlatformmay be more appropriate: its paths are in the file system it was given, which tests can replace.- Returns:
- the value
- Throws:
NoSuchElementException- if the property is not setInvalidPathException- if the value is not a path of the default file system
-
nativeEncoding
Returns the character encoding derived from the host environment and the user's settings: thenative.encodingproperty.- Returns:
- the value
- Throws:
NoSuchElementException- if the property is not setIllegalCharsetNameException- if the property is not a legal charset nameUnsupportedCharsetException- if this JVM does not support the charset the property names
-
stdinEncoding
Returns the character encoding ofSystem.in: thestdin.encodingproperty.- Returns:
- the value
- Throws:
NoSuchElementException- if the property is not setIllegalCharsetNameException- if the property is not a legal charset nameUnsupportedCharsetException- if this JVM does not support the charset the property names- Since:
- 0.2.0
-
stdoutEncoding
Returns the character encoding ofSystem.out: thestdout.encodingproperty.- Returns:
- the value
- Throws:
NoSuchElementException- if the property is not setIllegalCharsetNameException- if the property is not a legal charset nameUnsupportedCharsetException- if this JVM does not support the charset the property names
-
stderrEncoding
Returns the character encoding ofSystem.err: thestderr.encodingproperty.- Returns:
- the value
- Throws:
NoSuchElementException- if the property is not setIllegalCharsetNameException- if the property is not a legal charset nameUnsupportedCharsetException- if this JVM does not support the charset the property names
-
jdkModulePath
Returns the application module path, split on the path separator; empty when the application does not use one: thejdk.module.pathproperty.Supported by the JDK, not required by the Java SE specification.
The paths are in the default file system, as
Path.of(String, String...)makes them. APlatformmay be more appropriate: its paths are in the file system it was given, which tests can replace.- Returns:
- the value
- Throws:
NoSuchElementException- if the property is set but thepath.separatorproperty is notIllegalArgumentException- if the property is set but thepath.separatorproperty is emptyInvalidPathException- if an entry is not a path of the default file system
-
jdkModuleUpgradePath
Returns the upgrade module path, split on the path separator; empty when there is none: thejdk.module.upgrade.pathproperty.Supported by the JDK, not required by the Java SE specification.
The paths are in the default file system, as
Path.of(String, String...)makes them. APlatformmay be more appropriate: its paths are in the file system it was given, which tests can replace.- Returns:
- the value
- Throws:
NoSuchElementException- if the property is set but thepath.separatorproperty is notIllegalArgumentException- if the property is set but thepath.separatorproperty is emptyInvalidPathException- if an entry is not a path of the default file system
-
jdkModuleMain
-
jdkModuleMainClass
-
fileEncoding
Returns the name of the default charset. A name rather than aCharset: it can be set on the command line toCOMPAT, which is not a charset name: thefile.encodingproperty.Supported by the JDK, not required by the Java SE specification.
- Returns:
- the value, or empty if it is not set
-