java之的System类

 1 public class Demo3_System {
 2 
 3     /*
 4      * System类不能被实例化,所有的方法都是静态的
 5      * 成员方法:
 6      *   gc()   垃圾回收
 7      *   exit(int status)   退出程序 status 为0时是正常退出,非0位非正常退出
 8      *   public static long currentTimeMillis()  获取当前毫秒级时间
 9      *   public static void arraycopy(Object src, int srcPos, Object dest, int destpos, int length) 
10      *   拷贝相应长度的数组到对应的数组中
11      * 
12      */
13     public static void main(String[] args) {
14         //demo1();
15         //demo2();
16         //demo3();
17         demo4();
18     }
19 
20     /*
21      * 拷贝相应长度的数组中的值到目标数组中
22      */
23     public static void demo4() {
24         int[] src = {1, 2, 3, 4, 5};
25         int[] des = new int[8];
26         for (int i = 0; i < des.length; i++) {
27             System.out.println(des[i]);
28         }
29         System.out.println("********************");
30         System.arraycopy(src, 0, des, 0, src.length);
31         for (int i = 0; i < des.length; i++) {
32             System.out.println(des[i]);
33         }
34     }
35 
36     /*
37      * 获取当前时间的毫秒级时间
38      */
39     public static void demo3() {
40         System.out.println(System.currentTimeMillis());
41     }
42 
43     /*
44      * 退出程序
45      */
46     public static void demo2() {
47         System.out.println("正常运行");
48         System.exit(0);
49         System.out.println("结束了吗?");
50     }
51 
52     /*
53      * 调用垃圾回收机制
54      */
55     public static void demo1() {
56         new Demo();
57         System.gc();
58     }
59 }
60 
61 class Demo {
62 
63     //重写这个方法
64     @Override
65     protected void finalize() {
66         System.out.println("垃圾被回收了!");
67     }
68     
69 }

猜你喜欢

转载自www.cnblogs.com/jiangjunwei/p/9196966.html