Java System Class Learning notes

Source: Internet
Author: User

System classes in Java

Most common to System.out.println ();

The system class defined as public final class System extends object{} contains several useful class fields and methods, with the keyword final decoration, which indicates that this class cannot be inherited by another class.

It is constructed as private system{} (the construction method is privatized and cannot be instantiated externally).

There are three properties in System: In,out,err;

1.private final static InputStream in=null;

2.private final static PrintStream out=null;

--Out for class PrintStream type println () is the method in PrintStream. Out is final and static modified constants, so you can call the Out property with system, and then call the println () method.

3.private final static PrintStream err=null;

Several methods in the System:

The methods in System are all static decorated and can be called directly with the class name, such as System.getproperties ();

1,public static Properties getProperties () {} system.getproperties (). List (System.out); --Determines the current system properties.

2,public static string GetProperties (String key) {} system.getproperty (string key); -Gets the system properties specified by the current key.

3,public Static Long Currenttimemillis () {} system.currenttimemillis (); --Returns the current time in milliseconds.

public class s{public    static void main (string[] args) {        long starttime=system.currenttimemillis () ;        int a=0;        for (int i=0;i<1000000000;i++) {            a+=i;} long endtime=system.currenttimemillis (); System.out.println ("performed this program with" + (Endtime-starttime) + "milliseconds. "); }}

------------> Output is: It took 380 milliseconds to execute the program.

4,public static void Arraycopy (object src, int srcpos, object dest, int destpos, int length) {} Copies the array from the specified source array to the target array from the specified point Fixed position.

public class s{public    static void main (string[] args) {        int[] a=new int[]{1,2,3,10,20,30,4,5,6};        Int[] b=new int[3];        System.arraycopy (a,3,b,0,3);        for (int i=0;i<b.length;i++) {System.out.print (b[i]+ "");}}      

-------------> Output: Ten------> A for array A, 3 for a array of coordinates (TEN), B for array b,0 to represent the coordinates of the B array 0,3 for the length of the copy.

Java System Class Learning notes

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.