Get system properties using System class in java
/*
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.
*/
import java.util.Properties;
public class GetSystemProperties {
public static void main(String[] args) {
/*
* To get system properties use,
* static Properties getProperties() of System class.
*
* getProperties is a static method.
*
* Plase note that these properties are environment
* specific.
*/
Properties prop = System.getProperties();
System.out.println("Printing all System properties");
/*
* To print all system properties use
* static void list(PrintStream ps) method of System
* class.
*
* Hint : To print properties on console, paas
* System.out to list method.
*/
prop.list(System.out);
}
}
/*
TYPICAL output would be like,
Printing all System properties
-- listing properties --
java.assistive=ON
java.runtime.name=Java(TM) 2 Runtime Environment, Stand...
java.vm.version=1.3.1
java.vm.vendor=IBM Corporation
java.vendor.url=http://www.ibm.com/
path.separator=;
java.vm.name=Classic VM
....
*/
Comments
Post a Comment