java-System类

System类不能手动创建对象,因为构造方法被private修饰,阻止外界创建对象。System类中的都是static方法,类名访问即可。

常用方法

currentTimeMillis()   获取当前系统时间与1970年01月01日00:00点之间的毫秒差值

exit(int status) 用来结束正在运行的Java程序。参数传入一个数字即可。通常传入0记为正常状态,其他为异常状态

gc() 用来运行JVM中的垃圾回收器,完成内存中垃圾的清除。

getProperty(String key) 用来获取指定(字符串名称)中所记录的系统属性信息

 1 public class SystemDemo {
 2     public static void main(String[] args) {
 3         function_4();
 4     }
 5     /*
 6      * System类方法,复制数组
 7      * arraycopy(Object src, int srcPos, Object dest, int destPos, int length)
 8      * Object src, 要复制的源数组
 9      * int srcPos, 数组源的起始索引
10      * Object dest,复制后的目标数组
11      * int destPos,目标数组起始索引 
12      * int length, 复制几个
13      */
14     public static void function_4(){
15         int[] src = {11,22,33,44,55,66};
16         int[] desc = {77,88,99,0};
17         
18         System.arraycopy(src, 1, desc, 1, 2);
19         for(int i = 0 ;  i < desc.length ; i++){
20             System.out.println(desc[i]);
21         }
22     }
23     
24     /*
25      *  获取当前操作系统的属性
26      *  static Properties getProperties() 
27      */
28     public static void function_3(){
29         System.out.println( System.getProperties() );
30     }
31     
32     /*
33      *  JVM在内存中,收取对象的垃圾
34      *  static void gc()
35      */
36     public static void function_2(){
37         new Person();
38         new Person();
39         new Person();
40         new Person();
41         new Person();
42         new Person();
43         new Person();
44         new Person();
45         System.gc();
46     }
47     
48     /*
49      *  退出虚拟机,所有程序全停止
50      *  static void exit(0)
51      */
52     public static void function_1(){
53         while(true){
54             System.out.println("hello");
55             System.exit(0);
56         }
57     }
58     /*
59      *  获取系统当前毫秒值
60      *  static long currentTimeMillis()
61      *  对程序执行时间测试
62      */
63     public static void function(){
64         long start = System.currentTimeMillis();
65         for(int i = 0 ; i < 10000; i++){
66             System.out.println(i);
67         }
68         long end = System.currentTimeMillis();
69         System.out.println(end - start);
70     }
71 }
原文地址:https://www.cnblogs.com/zimo-bwl1029-s/p/9338556.html