System类

System类不能被实例化
主要方法:currentTimeMillis()   用于计算程序执行的时间
exit();     退出虚拟机
gc();       垃圾回收

public static void main(String[] args) {
        //用于计算程序执行的时间
        long t=System.currentTimeMillis();
        System.out.println(t);
        for(int i=0;i<100000;i++){
            System.out.println(i);
            
        }
        long end=System.currentTimeMillis();
        System.out.println(end-t);
        fun();

    }


    public static void fun(){
         new Person();
        new Person();
        new Person();
        new Person();
        new Person();
        new Person();
        new Person();
        new Person();
        System.gc();
        
    }

package cn.lijun.demo2;

public class Person {
    public void finalize(){
        System.out.println("垃圾被收走了");
    }

}

 

posted @ 2019-03-21 12:02  芯-觞  阅读(135)  评论(0编辑  收藏  举报