Java record-35-System class Parsing

Source: Internet
Author: User

Java record-35-System class Parsing
The java. lang class Systempublic final class System extends ObjectSystem class contains some useful class fields and methods. It cannot be instantiated. The facilities provided by the System class include standard input, standard output, and error output streams, access to externally defined attributes and environment variables, and methods for loading files and libraries; there is also a practical method to quickly copy part of the array. The System class represents the System. Many System-level attributes and control methods are placed inside the class. This class is located in the java. lang package. Because the constructor of this class is private, you cannot create an object of this class, that is, you cannot instantiate this class. The internal member variables and member methods are static, so they can be conveniently called. 1. The member variable System class contains three member variables: in, out, and err, representing the standard input stream (keyboard input) and standard output stream (Display) and standard error output stream (Display ). For example: System. out. println ("Test"); the function of this line of code is to output the string "Test" to the System's standard output device, that is, display on the screen. With IO knowledge, you can use the member methods in the System class to change the corresponding devices such as the standard input stream. For example, you can output the information output from the standard output stream to the file to form a log file. 2. Common member methods the System class provides some System-level operation methods. These methods implement the following functions: a. arraycopy public static void arraycopy (Object src, int srcPos, object dest, int destPos, int length) This method is used to copy an array, that is, to copy the content of an array to the specified position in another array, because this method is the native method, therefore, the performance is more efficient than loop. Example: int [] a = {1, 2, 3, 4}; int [] B = new int [5]; System. arraycopy (a, 1, B, 3, 2); this code is used to copy the subscript from array a to the position where array B starts from subscript 3, copy 2 in total. That is, copy a [1] to B [3] and copy a [2] to B [4]. After copying, the value in array a does not change, the value in array B is {0, 0, 0, 2, 3 }. B. currentTimeMillis method public static long currentTimeMillis () This method is used to return the current computer time. The time format is the current computer time and GMT time (Greenwich Mean Time) the number of milliseconds between 00:00:00, January 1, January 1, 1970. For example, long l = System. currentTimeMillis (); then, a long integer number is obtained, which is the current time expressed in a difference value. The time obtained by this method is not intuitive enough, but it facilitates time calculation. For example, the following code can be used to calculate the time required for running the program: long start = System. currentTimeMillis (); for (int I = 0; I <100000000; I ++) {int a = 0 ;}long end = System. currentTimeMillis (); long time = end-start; the value of the variable time here represents the number of milliseconds required for the for Loop execution in the middle of the Code, this method can be used to test the execution efficiency of programs with different algorithms, or to implement precise latency during later thread control. C. exit method public static void exit (int status). The function of this method is to exit the program. The value of status 0 indicates normal exit, and non-zero indicates abnormal exit. You can use this method to exit the program in graphic interface programming. D. gc method public static void gc () This method is used to request the system to recycle garbage. Whether the system recycles immediately depends on the implementation of the garbage collection algorithm in the system and the execution of the system. E. getProperty method public static String getProperty (String key) This method is used to obtain the value corresponding to the property named key in the system. The following table lists common attribute names and their functions. Attribute name attribute description java. version Java Runtime Environment version java. home Java installation directory OS. name OS. version: the version of the operating system. name user's account name user. home user's home directory user. the current working directory of the dir user, for example, String osName = System. getProperty ("OS. name "); String user = System. getProperty ("user. name "); System. out. println ("the current operating System is:" + osName); System. out. println ("current user is:" + user); using this method, you can obtain many system-level parameters and corresponding values.
Next article: http://www.bkjia.com/kf/201510/447453.html

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.