A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 琥珀主 中级黑马   /  2015-10-7 23:45  /  392 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

  1. public class Demo3_System {

  2.         /**
  3.          * * A:System类的概述
  4.                         * System 类包含一些有用的类字段和方法。它不能被实例化。
  5.                 * B:成员方法
  6.                         * public static void gc()
  7.                         * public static void exit(int status)
  8.                         * public static long currentTimeMillis()
  9.                         * pubiic static void arraycopy(Object src, int srcPos, Object dest, int destPos, int length)
  10.                 * C:案例演示
  11.                         * System类的成员方法使用
  12.          */
  13.         public static void main(String[] args) {
  14.                 //demo1();
  15.                 //demo2();
  16.                 //demo3();
  17.                
  18.                 int[] src = {11,22,33,44,55};
  19.                 int[] dest = new int[8];
  20.                 for (int i = 0; i < dest.length; i++) {
  21.                         System.out.println(dest[i]);
  22.                 }
  23.                
  24.                 System.out.println("--------------------------");
  25.                 System.arraycopy(src, 0, dest, 0, src.length);                //将数组内容拷贝
  26.                
  27.                 for (int i = 0; i < dest.length; i++) {
  28.                         System.out.println(dest[i]);
  29.                 }
  30.         }

  31.         public static void demo3() {
  32.                 long start = System.currentTimeMillis();                //1秒等于1000毫秒
  33.                 for(int i = 0; i < 1000; i++) {
  34.                         System.out.println("*");
  35.                 }
  36.                 long end = System.currentTimeMillis();                        //获取当前时间的毫秒值
  37.                
  38.                 System.out.println(end - start);
  39.         }

  40.         public static void demo2() {
  41.                 System.exit(1);                                                        //非0状态是异常终止,退出jvm
  42.                 System.out.println("11111111111");
  43.         }

  44.         public static void demo1() {
  45.                 for(int i = 0; i < 100; i++) {
  46.                         new Demo();
  47.                         System.gc();                                                //运行垃圾回收器,相当于呼喊保洁阿姨
  48.                 }
  49.         }

  50. }

  51. class Demo {                                                                        //在一个源文件中不允许定义两个用public修饰的类

  52.         @Override
  53.         public void finalize() {
  54.                 System.out.println("垃圾被清扫了");
  55.         }                                                       
  56.        
  57. }
复制代码

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马