Friday, January 4, 2013
Today I am going to post how you can display all the system properties with a simple Java program. You will need the java.util.Enumeration and java.util.Properties class. There is a method getProperties() defined in java.lang.System class. This method returns all the properties associated with your system as a Properties reference. Now we get an Enumeration of all keys of the properties. Next we iterate through each element of enumeration and get the value of individual keys and display them.
--------------------------------------------------------------------------------------------------------------------------
Java Source Code
--------------------------------------------------------------------------------------------------------------------------

import java.util.Enumeration;
import java.util.Properties;

public class SystemProperties{
public static void main (String[] args) {
Properties p=System.getProperties();  //getting system properties
Enumeration keys = p.keys();  //getting all keys of properties

        while (keys.hasMoreElements()) {
            String key = (String)keys.nextElement();  //getting next key
            String value = (String)p.get(key);  //getting key value
            System.out.println(key + ": " + value);
        }
    }
}
--------------------------------------------------------------------------------------------------------------------------
Output
--------------------------------------------------------------------------------------------------------------------------

java.runtime.name: Java(TM) SE Runtime Environment
sun.boot.library.path: C:\Program Files\Java\jdk1.7.0\jre\bin
java.vm.version: 21.0-b17
java.vm.vendor: Oracle Corporation
java.vendor.url: http://java.oracle.com/
path.separator: ;
java.vm.name: Java HotSpot(TM) Client VM
file.encoding.pkg: sun.io
user.country: US
user.script:
sun.java.launcher: SUN_STANDARD
sun.os.patch.level:
java.vm.specification.name: Java Virtual Machine Specification
user.dir: D:\Choto documents\Choto documents\Java Programs
java.runtime.version: 1.7.0-b147
java.awt.graphicsenv: sun.awt.Win32GraphicsEnvironment
java.endorsed.dirs: C:\Program Files\Java\jdk1.7.0\jre\lib\endorsed
os.arch: x86
java.io.tmpdir: C:\Users\Chelsea\AppData\Local\Temp\
line.separator:

java.vm.specification.vendor: Oracle Corporation
user.variant:
os.name: Windows 7
sun.jnu.encoding: Cp1252
java.library.path: C:\Program Files\Java\jdk1.7.0\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Program Files\PC Connectivity Solution\;C:\Program Files\Java\jdk1.7.0\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;.
java.specification.name: Java Platform API Specification
java.class.version: 51.0
sun.management.compiler: HotSpot Client Compiler
os.version: 6.1
user.home: C:\Users\Chelsea
user.timezone:
java.awt.printerjob: sun.awt.windows.WPrinterJob
file.encoding: Cp1252
java.specification.version: 1.7
java.class.path: D:\Java Programs;C:\Program Files\Java\jdk1.7.0\jre\lib\rt.jar;C:\Program Files\Java\jdk1.7.0\lib\dt.jar;C:\Program Files\Java\jdk1.7.0\lib\tools.jar;C:\Program Files\Java\jdk1.7.0\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.7.0\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.7.0\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.7.0\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.7.0\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.7.0\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.7.0\jre\lib\ext\zipfs.jar
user.name: -MadMickael/FFF
java.vm.specification.version: 1.7
sun.java.command: SystemProperties
java.home: C:\Program Files\Java\jdk1.7.0\jre
sun.arch.data.model: 32
user.language: en
java.specification.vendor: Oracle Corporation
awt.toolkit: sun.awt.windows.WToolkit
java.vm.info: mixed mode, sharing
java.version: 1.7.0
java.ext.dirs: C:\Program Files\Java\jdk1.7.0\jre\lib\ext;C:\Windows\Sun\Java\lib\ext
sun.boot.class.path: C:\Program Files\Java\jdk1.7.0\jre\lib\resources.jar;C:\Program Files\Java\jdk1.7.0\jre\lib\rt.jar;C:\Program Files\Java\jdk1.7.0\jre\lib\sunrsasign.jar;C:\Program Files\Java\jdk1.7.0\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.7.0\jre\lib\jce.jar;C:\Program Files\Java\jdk1.7.0\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.7.0\jre\classes
java.vendor: Oracle Corporation
file.separator: \
java.vendor.url.bug: http://bugreport.sun.com/bugreport/
sun.io.unicode.encoding: UnicodeLittle
sun.cpu.endian: little
sun.desktop: windows
sun.cpu.isalist: pentium_pro+mmx pentium_pro pentium+mmx pentium i486 i386 i86
--------------------------------------------------------------------------------------------------------------------------

Download Links
--------------------------------------------------------------------------------------------------------------------------
DOWNLOAD the source from Mediafire
DOWNLOAD the source from 4shared

1 comment:

Total Pageviews

Subscribe via Email

Followers


Popular Posts

About Me

My Photo

I am a student of BTech Computer Science Engineering from RCCIIT,Kolkata. I am a crazy lover of Java and wants to settle as a Java developer. I have a seven years Java experience with an application developer experience for 2 years. Recently from March 2012 I am a registered S40 app developer for Nokia and has corrected an app of them. I am currently writing blogs to encourage and grow interest in all those who don't know or learning Java.