First, the System class
1.
static long currentTimeMillis()
Returns the current time in milliseconds.
In fact: The time difference (measured in milliseconds) between the current and coordinated GMT January 1, 1970 midnight.
Long time = 1414069291407l;//long type followed by lSystem.out.println (time);
2.
static void exit (int status) terminates the currently running Java virtual machine.
static void GC () running the garbage collector
3. Focus
GetProperties determines the current system properties.
staticProperties
Import Java.util.properties;import Java.util.set;public class Main {//Get line break for current operating system public static final String Line_ SEPARATOR = System.getproperty ("Line.separator");p ublic static void Main (string[] args) {//Get system Property information and store it in the Properties collection The Properties collection stores all string-type key-value pairs, and package java.util.hashtable<object,object>//is best to use its own storage and fetch methods to complete element operations/* set< String> stringpropertynames () returns the set of keys in this property list, where the key and its corresponding value are strings, and if a key with the same name is not found in the main attribute list, the different keys in the default attribute list are also included. */Properties Pro = System.getproperties (); set<string> set = Pro.stringpropertynames (); for (string string:set) {String value = Pro.getproperty (string);//Key value System.out.println (string+ "-:-" +value);}// Set the property information to the system System.setproperty ("MyName", "xxxxxx");//This information is global, any program can call}}
Second, runtime class
When viewing the API documentation, it is clear that runtime does not have a constructor (stating that the object cannot be created), and that there is a non-static method in the method summary, which has a static getruntime () method, which shows that the runtime class is designed using a singleton design pattern.
Import Java.io.ioexception;public class Main {public static void main (string[] args) throws IOException, Interruptedexcep tion {Runtime r = runtime.getruntime ();//Return a process//execute: Execute xxxx.exe, call local a program, notice throw exception//r.exec ("notepad.exe");// This will be found in the current path, not found and then go to the pass path to find//Specify the path//r.exec ("C:\\xxx\\lol.exe"); note transfer character r.exec ("notepad.exe C:\\helloworld.java") ;//with XX program parsing xxx file, note file to match process P = r.exec ("notepad.exe"); Thread.Sleep (1000);//Display one second, kill, pay attention to throw abnormal p.destroy ();//Kill child Process}}
Third, the Math class
Extends Object
Note cannot be inherited
The math class covers a number of mathematical functions that can be challenged to learn, and the math method is static
The ratio of the circumference of the PI circle to the diameter E is the base of the natural logarithm and these two do not need to be defined directly
Import Java.io.ioexception;import Java.util.random;public class Main {public static void main (string[] args) {Double D1 = M Ath.ceil (11.51);//returns the smallest integer greater than the parameter double D2 = Math.floor (11.51);//returns the largest integer less than the parameter double D3 = Math.Round (11.51);// Returns rounded System.out.println (D1); System.out.println (D2); SYSTEM.OUT.PRINTLN (D3); System.out.println (Math.max (4, 5)); SYSTEM.OUT.PRINTLN ((int) Math.pow (2, 3));//Returns the B-order for (int i = 0; i <; i++) {System.out.println (int) (Math.random () *10));//0-9 random number//system.out.println (Math.floor (Math.random () *10));} Random ran = new random ();//random object//Returns the next pseudo-random number, which is a double value that is evenly distributed between 0.0 and 1.0, taken from this random number generator sequence. for (int i = 0;i<10;i++) {//system.out.println ((int) (ran.nextdouble () *6+1));//shorthand as follows int d = Ran.nextint (6) +1;// Nextint is the method in random System.out.println (d);}}
Java Learning Lesson 45th-Other Object APIs (i)