Bi Xiangdong Teacher Java Basic Learning Note--system Object
After learning about the system object in Java today, it is important for us to feel this object for the following useful purposes.
1. Get the current operating system version and type.
2. Gets the environment variables in the path of the current operating system.
The sample code is as follows:
/*System: Methods and properties in a class are static. Out: Standard output, default is console. In: standard input, default is keyboard. Describe the system some information Get system property information: Propcrtics*/ImportJava.util.*;classsystemdemo{ Public Static voidMain (string[] args) {Properties prop=system.getproperties (); //because properties is a subclass of Hashtable, which is a subclass object of the collection of maps. //then the elements in the collection can be extracted by means of a map. //The collection is stored in a string and has no generic definition. //How do you customize some of the unique information in your system? //system.setproperty ("MyKey", "Nebula"); //Get all property value informationSystem.out.println ("+--------get all property information---------------+"); for(Object obj:prop.keySet ()) {String value=(String) prop.get (obj); System.out.println (obj+"::"+value); } System.out.println ("+--------Get the specified attribute information---------------+"); //gets the specified property informationString value=system.getproperty ("Os.name"); System.out.println ("Gets the specified operating system property information for:" +value); //is it possible to load some information dynamically when the JVM starts?
Note: To run the following code, be sure to follow the format: Java-dhaha=ssssssss Systemdemo. String v=system.getproperty ("haha"); System.out.println ("V=" +v); }}
normal operation Please enter :
javac Systemdemo.java Java Systemdemo
Program:
To use dynamic loading for some information, enter:
javac Systemdemo.java - dhaha=ssssssss Systemdemo
Program:
1.Java Base System Object