How do I list System properties?
Author: Deron Eriksson
Description: This Java tutorial shows how to list System properties.
Tutorial created using:
Windows XP || JDK 1.5.0_09 || Eclipse Web Tools Platform 1.5.1
The System Properties object is a set of key/value pairs that stores information about the current runtime environment. This information includes things such as the JavaSW version, Operating System version, user name, etc. The ListSystemProperties class shows how to output the system properties to standard output. A Properties object is obtained via System.getProperties(), and the property keys (or 'names') are enumerated over, and the value is looked up for each key. The property key (name) and property value are displayed for each pair. ListSystemProperties.javapackage test; import java.util.Enumeration; import java.util.Properties; public class ListSystemProperties { public static void main(String[] args) { Properties systemProperties = System.getProperties(); Enumeration enuProp = systemProperties.propertyNames(); while (enuProp.hasMoreElements()) { String propertyName = (String) enuProp.nextElement(); String propertyValue = systemProperties.getProperty(propertyName); System.out.println(propertyName + ": " + propertyValue); } } } The results of the execution of ListSystemProperties on my system are displayed below. results.txtjava.runtime.name: Java(TM) 2 Runtime Environment, Standard Edition sun.boot.library.path: C:\jdk1.5.0_09\jre\bin java.vm.version: 1.5.0_09-b03 java.vm.vendor: Sun Microsystems Inc. java.vendor.url: http://java.sun.com/ path.separator: ; java.vm.name: Java HotSpot(TM) Client VM file.encoding.pkg: sun.io user.country: US sun.os.patch.level: Service Pack 2 java.vm.specification.name: Java Virtual Machine Specification user.dir: C:\projects\workspace\testing java.runtime.version: 1.5.0_09-b03 java.awt.graphicsenv: sun.awt.Win32GraphicsEnvironment java.endorsed.dirs: C:\jdk1.5.0_09\jre\lib\endorsed os.arch: x86 java.io.tmpdir: C:\DOCUME~1\Deron\LOCALS~1\Temp\ line.separator: java.vm.specification.vendor: Sun Microsystems Inc. user.variant: os.name: Windows XP sun.jnu.encoding: Cp1252 java.library.path: C:\jdk1.5.0_09\jre\bin;.;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\QuickTime\QTSystem\;C:\jdk1.5.0_09\bin;C:\maven-2.0.4\bin;C:\jadnt158; java.specification.name: Java Platform API Specification java.class.version: 49.0 sun.management.compiler: HotSpot Client Compiler os.version: 5.1 user.home: C:\Documents and Settings\Deron user.timezone: java.awt.printerjob: sun.awt.windows.WPrinterJob file.encoding: Cp1252 java.specification.version: 1.5 user.name: Deron java.class.path: C:\projects\workspace\testing\bin java.vm.specification.version: 1.0 sun.arch.data.model: 32 java.home: C:\jdk1.5.0_09\jre java.specification.vendor: Sun Microsystems Inc. user.language: en awt.toolkit: sun.awt.windows.WToolkit java.vm.info: mixed mode java.version: 1.5.0_09 java.ext.dirs: C:\jdk1.5.0_09\jre\lib\ext sun.boot.class.path: C:\jdk1.5.0_09\jre\lib\rt.jar;C:\jdk1.5.0_09\jre\lib\i18n.jar;C:\jdk1.5.0_09\jre\lib\sunrsasign.jar;C:\jdk1.5.0_09\jre\lib\jsse.jar;C:\jdk1.5.0_09\jre\lib\jce.jar;C:\jdk1.5.0_09\jre\lib\charsets.jar;C:\jdk1.5.0_09\jre\classes java.vendor: Sun Microsystems Inc. file.separator: \ java.vendor.url.bug: http://java.sun.com/cgi-bin/bugreport.cgi sun.cpu.endian: little sun.io.unicode.encoding: UnicodeLittle sun.desktop: windows sun.cpu.isalist: pentium_pro+mmx pentium_pro pentium+mmx pentium i486 i386 i86 Related Tutorials:
|