Get system properties using System class.
This example shows how to get system properties using System class. This example also shows how to get and print all system properties.
package com.crunchify.tutorials; /** * @author Crunchify.com */ import java.lang.management.ManagementFactory; import java.lang.management.RuntimeMXBean; import java.util.Map; import java.util.Set; public class CrunchifyGetSystemProperties { public static void main(String[] args) { RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean(); Map<String, String> systemProperties = runtimeBean.getSystemProperties(); Set<String> keys = systemProperties.keySet(); for (String key : keys) { String value = systemProperties.get(key); System.out.printf("[%s] = %s.\n", key, value); } } }
Output:
[java.vm.version] = 21.0-b17. [sun.jnu.encoding] = Cp1252. [java.vendor.url] = http://java.oracle.com/. [java.vm.info] = mixed mode. [user.dir] = C:\eclipse-4.2.1ee\Crunchify\workspace\CrunchifyExamples. [sun.cpu.isalist] = amd64. [java.awt.graphicsenv] = sun.awt.Win32GraphicsEnvironment. [sun.os.patch.level] = Service Pack 1. [java.io.tmpdir] = C:\Users\user1\AppData\Local\Temp\. [user.home] = C:\Users\user1. [java.awt.printerjob] = sun.awt.windows.WPrinterJob. [java.version] = 1.7.0. [file.encoding.pkg] = sun.io. [java.vendor.url.bug] = http://bugreport.sun.com/bugreport/. [file.encoding] = Cp1252. [line.separator] = [sun.java.command] = com.crunchify.tutorials.CrunchifyGetSystemProperties. [java.vm.specification.vendor] = Oracle Corporation. [java.vm.vendor] = Oracle Corporation. [java.class.path] = ..... [sun.io.unicode.encoding] = UnicodeLittle. [user.variant] = . [os.arch] = amd64. [user.name] = user1. [user.language] = en. [java.runtime.version] = 1.7.0-b147. [sun.boot.class.path] = ..... [sun.desktop] = windows. [sun.cpu.endian] = little. [awt.toolkit] = sun.awt.windows.WToolkit. [sun.boot.library.path] = C:\Program Files\Java\jdk1.7.0\jre\bin. [java.vm.name] = Java HotSpot(TM) 64-Bit Server VM. [java.home] = C:\Program Files\Java\jdk1.7.0\jre. [java.endorsed.dirs] = C:\Program Files\Java\jdk1.7.0\jre\lib\endorsed. [sun.management.compiler] = HotSpot 64-Bit Tiered Compilers. [java.runtime.name] = Java(TM) SE Runtime Environment. [java.library.path] = ..... [file.separator] = \. [java.specification.vendor] = Oracle Corporation. [java.vm.specification.version] = 1.7. [sun.java.launcher] = SUN_STANDARD. [user.timezone] = . [os.name] = Windows 7. [path.separator] = ;. [java.ext.dirs] = C:\Program Files\Java\jdk1.7.0\jre\lib\ext;C:\windows\Sun\Java\lib\ext. [sun.arch.data.model] = 64. [java.specification.name] = Java Platform API Specification. [os.version] = 6.1. [user.script] = . [user.country] = US. [java.class.version] = 51.0. [java.vendor] = Oracle Corporation. [java.vm.specification.name] = Java Virtual Machine Specification. [java.specification.version] = 1.7.