How do I get system properties information?

package org.kodejava.lang.management;

import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.util.Map;
import java.util.Set;

public class GetSystemProperties {
    public static void main(String[] args) {
        RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean();

        // Returns a map of names and values of all system
        // properties. This method calls System.getProperties()
        // to get all system properties. Properties whose
        // name or value is not a String are omitted.
        Map<String, String> systemProperties = bean.getSystemProperties();
        Set<String> keys = systemProperties.keySet();
        for (String key : keys) {
            String value = systemProperties.get(key);
            System.out.printf("Property[%s] = %s%n", key, value);
        }
    }
}

Some properties produced by the code snippet above are:

Property[java.specification.version] = 17
Property[sun.cpu.isalist] = amd64
Property[sun.jnu.encoding] = Cp1252
Property[java.vm.vendor] = Oracle Corporation
Property[sun.arch.data.model] = 64
Property[user.variant] = 
Property[java.vendor.url] = https://java.oracle.com/
...
...
Property[java.vm.info] = mixed mode, sharing.
Property[java.vendor] = Oracle Corporation.
Property[java.vm.version] = 17+35-LTS-2724.
Property[sun.io.unicode.encoding] = UnicodeLittle.
Property[java.class.version] = 61.0.
Wayan

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.