System
Get system properties with System
With this example we are going to demonstrate how to get system properties. We are using the System class, that contains several useful class fields and methods. In short, to get system properties with System class you should:
- Call
getProperties()
API method of System. This method determines the current system properties. It returns an object of the Properties class, that represents a persistent set of properties. The Properties can be saved to a stream or loaded from a stream. Each key and its corresponding value in the property list is a string.
Let’s take a look at the code snippet that follows:
package com.javacodegeeks.snippets.core; import java.util.Properties; public class GetSystemPropertiesWithSystem { public static void main(String[] args) { // Determines the current system properties Properties prop = System.getProperties(); prop.list(System.out); } }
Output:
-- listing properties --
java.runtime.name=Java(TM) SE Runtime Environment
sun.boot.library.path=C:Program Files (x86)Javajdk1.6.0_...
java.vm.version=10.0-b19
java.vm.vendor=Sun Microsystems Inc.
java.vendor.url=http://java.sun.com/
...
This was an example of how to get system properties with System class in Java.