System class and its common functions

Source: Internet
Author: User
Tags time in milliseconds

SystemThe 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.