System, which represents the program, provides the corresponding system property information, and system operation. The system class cannot create objects manually because the constructor method is private and prevents objects from being created by the outside world. The system class is a static method, and the class name is accessed.
Common methods:
L currenttimemillis() Gets the millisecond difference between the current system time and the January 01, 1970 00:00 Point
L exit (int status) is used to end a running Java program. parameter to pass in a number. Typically incoming 0 is recorded as normal, others are in an abnormal state
The GC () is used to run the garbage collector in the JVM to complete the removal of garbage in memory.
L GetProperty (string key) is used to get system property information that is recorded in the specified key (string name)
The L arraycopy method, which is used to implement copying a portion of a source array to a specified location in the destination array
Method exercises for the system class:
L Practice One: Verify the time required to print the number 1-9999 for the For Loop (MS)
public static void Main (string[] args) { long start = System.currenttimemillis (), for (int i=0; i<10000; i++) { System.out.println (i);} Long end = System.currenttimemillis (); SYSTEM.OUT.PRINTLN ("Total time-consuming milliseconds:" + (End-start));}
L Practice II: Copy the first 3 elements of the SRC array to the first 3 positions of the dest array
Before copying an element: src array element [1,2,3,4,5],dest array element [6,7,8,9,10]
After copying an element: src array element [1,2,3,4,5],dest array element [1,2,3,9,10]
public static void Main (string[] args) {int[] src = new int[]{1,2,3,4,5};int[] dest = new int[]{6,7,8,9,10}; System.arraycopy (src, 0, dest, 0, 3); After code runs: two elements in an array have changed src array element [1,2,3,4,5]dest array element [1,2,3,9,10]}
L Exercise three: loop to generate three digits between 100-999 and print that number, when the number can be divisible by 10, the end of the running program
public static void Main (string[] args) { random random = new random (), while (true) { int number = Random.nextint (900 ) +100; 0-899 + if (nmumber% = = 0) { system.exit (0);}}}
The system class for Java common APIs