您的位置:首页 > 编程语言 > Java开发

Java 基础类库(System类)

2018-03-21 17:11 501 查看
public class Demo {
public static void main(String[] args) throws Exception {
long start = System.currentTimeMillis();
String str = "";
for (int i = 0; i < 2000; i++) {
str += i;
}
long end = System.currentTimeMillis();
System.out.println("本次操作所用时间:" + (end - start));
}

}

/*
* Object类提供的finalize方法protect void finalize() throws Throwble
*/
class Message {
public Message() {
System.out.println("绝地求生!");
}

@Override
protected void finalize() throws Throwable {
System.out.println("落地成盒!");
throw new Exception("大吉大利!今晚吃鸡!");
}
}

public class Demo {
public static void main(String[] args) throws Exception {
Message msg = new Message();
msg = null;// 形成垃圾
System.gc();//System的gc()方法间接调用Runtime.getRuntime.gc()的方法

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Java 基础类库 System