Friday, August 27, 2010

Java : Simple program to get system properties

If you want to know your system properties or you want to create properties file listing all properties of your system. Lets see a simple java program which lists all system properties of your computer.

/* MySystemProperties.java */

import java.util.Iterator;
import java.util.Properties;
import java.util.Set;

public class MySystemProperties {
  
    public static void main(String[] args) {
      
        System.out.println("# My System Properties");
      
        Properties properties = System.getProperties();
      
        Set<String> propertiesSet = properties.stringPropertyNames();
      
        Iterator<String> iterator =  propertiesSet.iterator();
      
        String name;
      
        while (iterator.hasNext()) {
          
            name = iterator.next();
            System.out.println(name+" = "+properties.getProperty(name));
        }
      
    }

}


Output (output may differ depending on your computers properties)

# My System Properties
java.runtime.name = Java(TM) SE Runtime Environment
sun.boot.library.path = C:\Program Files\Java\jre6\bin
java.vm.version = 17.0-b17
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.java.launcher = SUN_STANDARD
sun.os.patch.level = Service Pack 3
java.vm.specification.name = Java Virtual Machine Specification
user.dir = C:\MY\Code\Test
java.runtime.version = 1.6.0_21-b07
java.awt.graphicsenv = sun.awt.Win32GraphicsEnvironment
java.endorsed.dirs = C:\Program Files\Java\jre6\lib\endorsed
os.arch = x86
java.io.tmpdir = c:\temp\
line.separator =

java.vm.specification.vendor = Sun Microsystems Inc.
user.variant =
os.name = Windows XP
sun.jnu.encoding = Cp1252
java.library.path = C:\WINXP\system32;.;C:\WINXP\Sun\Java\bin;C:\WINXP\system32;C:\WINXP;C:\WINXP\system32;C:\WINXP\;C:\WINXP\System32\Wbem;C:\WINXP\system32\nls;C:\WINXP\system32\nls\ENGLISH;C:\Program Files\UltraEdit\;C:\Program Files\CA\SC\CAWIN\;C:\Program Files\IBM\Personal Communications\;C:\Program Files\IBM\Trace Facility\;C:\WINXP\system32;C:\WINXP;C:\WINXP\System32\Wbem;C:\WINXP\system32\nls;C:\WINXP\system32\nls\ENGLISH;c:\Program Files\Novell\ZENworks\;C:\PROGRA~1\CA\SC\CAM\bin;C:\Program Files\CA\DSM\bin;C:\Program Files\SSH\SecureCRT\;C:\Program Files\SSH\SecureFX\;C:\Program Files\Rational\common;C:\Program Files\SQLLIB\FUNCTION;C:\Program Files\SQLLIB\help\;C:\Program Files\SQLLIB\samples\repl\;C:\Program Files\IBM\IMNNQ\;C:\Program Files\SQLLIB\bin\;C:\PROGRA~1\IBM\SQLLIB\BIN;C:\PROGRA~1\IBM\SQLLIB\FUNCTION;C:\Program Files\Java\jre6\bin;C:\Program Files\Java\jdk1.6.0_21\bin;C:\Program Files\Java\jdk1.6.0_21\bin;C:\Program Files\Java\jre6\bin;Z:.;Y:.;X:.
java.specification.name = Java Platform API Specification
java.class.version = 50.0
sun.management.compiler = HotSpot Client Compiler
os.version = 5.1
user.home = C:\Documents and Settings\madan
user.timezone =
java.awt.printerjob = sun.awt.windows.WPrinterJob
file.encoding = Cp1252
java.specification.version = 1.6
user.name = madan
java.class.path = .
java.vm.specification.version = 1.0
sun.arch.data.model = 32
java.home = C:\Program Files\Java\jre6
java.specification.vendor = Sun Microsystems Inc.
user.language = en
awt.toolkit = sun.awt.windows.WToolkit
java.vm.info = mixed mode, sharing
java.version = 1.6.0_21
java.ext.dirs = C:\Program Files\Java\jre6\lib\ext;C:\WINXP\Sun\Java\lib\ext
sun.boot.class.path = C:\Program Files\Java\jre6\lib\resources.jar;C:\Program Files\Java\jre6\lib\rt.jar;C:\Program Files\Java\jre6\lib\sunrsasign.jar;C:\Program Files\Java\jre6\lib\jsse.jar;C:\Program Files\Java\jre6\lib\jce.jar;C:\Program Files\Java\jre6\lib\charsets.jar;C:\Program Files\Java\jre6\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

No comments:

Post a Comment