package com.fish.other;import java.util.arrays;import java.util.properties;/*system System class is primarily used to obtain the system's attribute data. Common methods of system class: arraycopy (Object src, int srcpos, object dest, int destpos, int length) General src - source array. The starting position in the srcPos - source array. dest - target array. destPos - the starting position in the target data. length - the number of array elements to copy. currenttimemillis () get current system system. key exit (int status) exit jvm If the parameter is 0 to exit the JVM normally, not 0 indicates an exception to exit the JVM. General &NBSP;&NBSP;&NBSP;GC () It is recommended that the JVM start recycling garbage during garbage collection. getenv (string name) Gets environment variables based on the name of the environment variable. getproperty (Key) Finalize () If an object is reclaimed by garbage collection , the object's Finalize () method is called first. */ class Person{ String name; public person (String name) { this.name = name; } @Override public void finalize () throws Throwable { super.finalize (); system.out.println (this.name+ "was recycled.."); }}public class Demo1 { public static Void main (String[] args) { /* int[] srcArr = {10,12,14,16,19}; //put SCopies the array elements of the Rcarr into the Destarr array. int[] destArr = new int[4]; system.arraycopy (srcarr, 1, destarr, 0,4); //system.exit (0); &NBSP;//JVM exit: Note: 0 or non-0 data can exit the JVM. There is no difference for the user. Exit (0) is typically used in a try block, with exit (1) in the CATCH block system.out.println ("Elements of the target array:" + arrays.tostring (Destarr)); // 0 14 16 &NBSP;0&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;SYSTEM.OUT.PRINTLN ("Current system time:" + System.currenttimemillis ()); &nbsP SYSTEM.OUT.PRINTLN ("Environment variable:" +system.getenv ("Java_home")); for (int i = 0 ; i<4; i++) { new person ("Dog Doll" +i); system.gc (); //recommended to start the garbage collection period immediately } properties properties = system.getproperties (); //gets all the properties of the system. properties.list (System.out); */ string value = system.getproperty ("Os.name");//get the corresponding attribute value according to the system's property name &NBSP;&NBSP;&NBSP;&NBSP;SYSTEM.OUT.PRINTLN ("Current system:" +value); }}
Package com.fish.other;import java.io.ioexception;import javax.management.runtimeerrorexception ;/* runtime This class of classes mainly represents the environment in which the application runs. getruntime () returns the running environment object for the current application. exec (String command) executes the corresponding executable file according to the specified path. freememory () back Java amount of free memory in the virtual machine. in bytes maxmemory () return Java The maximum amount of memory that the virtual machine is trying to use. totalmemory () return Java total memory in virtual machines */public class Demo2 { public static void Main (String[] args) throws IOException, InterruptedException { runtime runtime = runtime.getruntime (); &nbsP; //process process = runtime.exec ("C:\\Windows \\notepad.exe "); //let the current program stop for 3 seconds. //process.destroy (); SYSTEM.OUT.PRINTLN ("The amount of idle memory in the java virtual machine. "+runtime.freememory ()); system.out.println (" Java Maximum amount of memory that the virtual machine is trying to use: "+ runtime.maxmemory ())"; system.out.println ( "Return Java total Memory in virtual machine:" + runtime.totalmemory ()); }}
This article from "Small Fish Blog" blog, declined reprint!
Java System, Runtime class