Code
---------
public class SystemProperties {
public static void main(String[] args) {
System.out.println(System.getProperty("java.home"));
System.out.println(System.getProperty("os.name"));
System.out.println(System.getenv("windir"));
}
}
---------
public class SystemProperties {
public static void main(String[] args) {
System.out.println(System.getProperty("java.home"));
System.out.println(System.getProperty("os.name"));
System.out.println(System.getenv("windir"));
}
}
Sample output
------------------
C:\Program Files\Java\jre7
Windows 7
C:\Windows
Explanation
--------------------
java.home: It is the property for which the value is the java home, the directory where Java is installed in the PC in which this program is executed.
getProperty(): This is a method of java.lang.System class which takes property name and returns property values.
System.getProperty("os.name"): This method is used for getting the value of specified property in Java. The os.name property means the name of the OS.
System.getenv(): Takes a property name and returns its value. env means environment.
No comments:
Post a Comment