zoukankan      html  css  js  c++  java
  • 《第一行代码-李兴华》-10.3 System类

    10.3 System类

    视频地址System类

    /**
     * 
     * 统计某项操作执行时间
     *
     */
    long start = System.currentTimeMillis();//返回以毫秒为单位的当前时间。
      String str ="";
      for(int i=0;i<10000;i++) {
       str +=i;
      }
      long end = System.currentTimeMillis();
      System.out.println("本次操作用时"+(end-start));  
    
    
    class Devil{
     public Devil() {
      System.out.println("天崩地裂,魔鬼出世");
     }
     @Override
     protected void finalize() throws Throwable {//对象回收方法
      System.out.println("魔鬼死了,全世界庆贺!!");
      throw new Exception("老子下个世纪还要祸害地球!于是嗝屁了");
     }
    }
    public class TestDemo {
     public static void main(String args[]) throws Exception {
      Devil devil = new Devil();  //实例化新对象
      devil=null;      //产生垃圾
      System.gc();     //手工处理垃圾收
     }
    }
    
    面试题

    请解释final、finally、finallize的区别

    • final:关键字,定义不能被继承的类、不能被覆写的方法、常量;
    • finally:关键字,异常的统一出口;
    • finallize:方法,Object类提供的方法(protected void finalize() throws Throwable)即使出现异常也不会中断
    总结
    1. System类可以使用currentTimeMillis()方法取得当前系统时间;
    2. System类gc()方法直接调用“Runtime.getRuntime().gc()”方法
  • 相关阅读:
    read 命令详解
    rpm 命令详解
    random 模块
    time 模块
    Numpy 数据类型和基本操作
    numpy 数组对象
    netstat 命令详解
    free 命令详解
    Python中*args和**kwargs 的简单使用
    Numpy 数组简单操作
  • 原文地址:https://www.cnblogs.com/xuwei1/p/8458358.html
Copyright © 2011-2022 走看看