JAVA学习笔记09

System类

 

* A:System类的概述
  * System 类包含一些有用的类字段和方法。它不能被实例化。
* B:成员方法
  * public static void gc()
  * public static void exit(int status)
  * public static long currentTimeMillis()
  * pubiic static void arraycopy(Object src, int srcPos, Object dest, int destPos, int length)
* C:案例演示
  * System类的成员方法使用

 1 package com.miao.lianxi;
 2 public class Demo3_System {
 3 
 4     public static void main(String[] args) {
 5         //demo1();
 6         //demo2();
 7         //demo3();
 8         
 9         int[] src = {11,22,33,44,55};
10         int[] dest = new int[8];
11         for (int i = 0; i < dest.length; i++) {
12             System.out.println(dest[i]);
13         }
14         
15         System.out.println("--------------------------");
16         System.arraycopy(src, 0, dest, 0, src.length);        //将数组内容拷贝
17         
18         for (int i = 0; i < dest.length; i++) {
19             System.out.println(dest[i]);
20         }
21     }
22 
23     public static void demo3() {
24         long start = System.currentTimeMillis();        //1秒等于1000毫秒
25         for(int i = 0; i < 1000; i++) {
26             System.out.println("*");
27         }
28         long end = System.currentTimeMillis();            //获取当前时间的毫秒值
29         
30         System.out.println(end - start);
31     }
32 
33     public static void demo2() {
34         System.exit(1);                            //非0状态是异常终止,退出jvm
35         System.out.println("11111111111");
36     }
37 
38     public static void demo1() {
39         for(int i = 0; i < 100; i++) {
40             new Demo();
41             System.gc();                        //运行垃圾回收器,相当于呼喊保洁阿姨
42         }
43     }
44 
45 }
46 
47 class Demo {                                    //在一个源文件中不允许定义两个用public修饰的类
48 
49     @Override
50     public void finalize() {
51         System.out.println("垃圾被清扫了");
52     }                            
53     
54 }

 

posted @ 2019-02-13 18:16  淼喵  阅读(100)  评论(0)    收藏  举报