First, describe
There are two ways to get the properties of a system in Java:
1. You can use the methods in the System class: public static Properties GetProperties () gets the various properties
The method returns a properties class that inherits from Hashtable and defines key-value pairs for various properties in the class.
2. Use System.getproperty (String key) directly to get the desired system properties.
In fact, the two are equivalent, and the System.getproperty (string key) method internally invokes the GetProperty (string key) method of the Properties object declared inside the System class.
Second, the source code
Package Tong.day4_27.systemuse;import java.util.properties;/** * There are two ways to get the properties of a system in Java: * 1, you can use the methods in the System class: public Static Properties GetProperties () Gets the various properties of the system, * This method returns a properties class, which inherits from Hashtable, which defines the key-value pairs for various properties in the class. * 2, directly using System.getproperty (string key) to get the required system properties * In fact, the two are equivalent, System.getproperty (string key) Method internally invokes the GetProperty (String key) method of the Properties object declared inside the system class * @author Tong * */public class Propertiesuse {/** * @param args */public static void Main (string[] args) {//using propertiesproperties properties = System.getproperties (); System.out.println ("Java Version number:"); System.out.println (Properties.getproperty ("java.version")); System.out.println ("Java Vendor:"); System.out.println (Properties.getproperty ("Java.vendor")); System.out.println ("Java Vendor URL:"); System.out.println (Properties.getproperty ("Java.vendor.url")); System.out.println ("***********");//Direct use of the System.getproperty () method System.out.println ("Java Version number:"); System.out.println (System.getproperty ("java.version")); System.out.println ("Java Vendor:"); System.out.println (systeM.getproperty ("Java.vendor")); System.out.println ("Java Vendor URL:"); System.out.println (System.getproperty ("Java.vendor.url")); System.out.println ("User name:"); System.out.println (System.getproperty ("User.Name")); System.out.println ("User runs the program's current directory:"); System.out.println (System.getproperty ("User.dir")); System.out.println ("User home directory:"); System.out.println (System.getproperty ("Uer.home")); System.out.println ("File delimiter:"); System.out.println (System.getproperty ("File.separator")); SYSTEM.OUT.PRINTLN ("Operating system name:"); System.out.println (System.getproperty ("Os.name")); SYSTEM.OUT.PRINTLN ("OS version number:"); System.out.println (System.getproperty ("os.version"));}}
Operation Result:
List of other System properties in Java:
GetProperties () and GetProperty (String) of the system class are used in Java to get the properties of the current systems