System
The class contains some useful class fields and methods. It cannot be instantiated.
Common methods:
1. static void
arraycopy(Object src, int srcPos, Object dest, int destPos, int length)
Copies an array from the specified source array, starting at the specified location and ending at the specified position in the destination array.
2. static long
currentTimeMillis()
Returns the current time in milliseconds.
3. static void
gc()
Run the garbage collector. It is recommended that the JVM quickly start recycling garbage during garbage collection.
4. static Map<String,String>
getenv()
Returns a string-mapped view of the current system environment that cannot be modified.
5. static String
getenv(String name)
Gets the specified environment variable value.
6. static Properties
getProperties()
Determines the current system properties.
7. static String
getProperty(String key)
Gets the system properties indicated by the specified key.
8. static void
exit(int status)
Terminates the currently running Java virtual machine. By convention, a status code other than 0 indicates an abnormal termination. 0 indicates normal termination.
The code examples are as follows:
1 Importjava.util.Arrays;2 Importjava.util.Properties;3 4 classperson{5 6 String name;7 8 PublicPerson (String name) {9 This. Name =name;Ten } One A @Override - protected voidFinalize ()throwsThrowable { - Super. Finalize (); theSystem.out.println ( This. Name + "was released"); - } - - } + - Public classSystemtest { + A Public Static voidMain (string[] args) { at //arraycopy (object src, int srcpos, object dest, int destpos, int length) - int[] Srcarray = {1,2,5,8,45,12}; - int[] Desarray =New int[4]; -System.arraycopy (Srcarray, 2, Desarray, 0, 4); - System.out.println (arrays.tostring (Desarray)); - //Currenttimemillis () in LongCurrentTime =System.currenttimemillis (); - System.out.println (currenttime); to //It is recommended that the JVM start the garbage collector garbage collection quickly + for(inti = 0; I < 4; i++) { - NewPerson ("Zhang San" +i); the System.GC (); * } $ //Get Environment VariablesPanax NotoginsengSYSTEM.OUT.PRINTLN ("Environment variable list" +system.getenv ()); -SYSTEM.OUT.PRINTLN ("Java_home environment variable list" +system.getenv ("Java_home")); the //Get System Properties +Properties Properties =system.getproperties (); A properties.list (System.out); theString Propertie = System.getproperty ("Os.version"); +SYSTEM.OUT.PRINTLN ("System version:" +propertie); - //shutdown JVM 0 normal off 1 abnormal off $System.exit (0); $System.out.println ("Do not execute after closing"); - } - the}
View Code
System class and its common functions