System类

作者: 廷裕同学 | 来源:发表于2020-01-09 14:32 被阅读0次

System 系统类:主要的作用是用于获取系统的一些参数。

需要掌握的方法:

- static void arraycopy(Object src, int srcPos, Object dest, int destPos, int length)
    参数:
        src - 源数组。
        srcPos - 源数组中的起始位置。
        dest - 目标数组。
        destPos - 目标数据中的起始位置。
        length - 要复制的数组元素的数量。

- static long currentTimeMillis()
    获取当前的系统时间

- static void exit(int status)
    退出jvm,0表示正常退出jvm,非0表示异常退出

- static void gc()
    建议jvm尽快启动垃圾回收器

- static String getenv(String name)
    获取系统环境变量

- static String getProperty(String key)
    获取系统属性
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Properties;
class Persion{
    String name;

    public Persion(String name) {
        this.name = name;
    }


    @Override
    protected void finalize() throws Throwable{
        super.finalize();
        System.out.println(this.name+"我被回收了");
    }

}
public class Demo1 {
    public static void main(String args[]){
        int[] arr1 = {10,9,4,19};
        int[] arr2 = new int[4];
        System.arraycopy(arr1,1,arr2,2,2);
        System.out.println("拷贝后的数组是:"+Arrays.toString(arr2));
        System.out.println("当前的时间戳是:"+(int)(System.currentTimeMillis()/1000));
        for (int i=0;i<10;i++){
            new Persion("张三"+i);
            System.gc(); // 任何对象被回收之前都会调用对象的finalize()方法
        }
        System.gc();
        String path = System.getenv("PATH");
        System.out.println(path);
//        Properties p = System.getProperties();
//        p.list(System.out);
        System.out.println(System.getProperty("os.name"));
//        System.exit(0);
    }
}

控制台输出

拷贝后的数组是:[0, 0, 9, 4]
当前的时间戳是:1578551271
张三0我被回收了
张三9我被回收了
张三8我被回收了
张三7我被回收了
张三6我被回收了
张三5我被回收了
张三4我被回收了
张三3我被回收了
张三2我被回收了
张三1我被回收了
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
Mac OS X

相关文章

  • System 类

    System 类包含一些有用的类字段和方法。它不能被实例化。 在 System 类提供的设施中,有标准输入、标准输...

  • System类

    System类  1.Sysytem类是一个静态类   方法为静态的,由类名来调用,构造方法私有.  2.curr...

  • System类

    1.如果计算某个代码的执行时间2.进行垃圾收集操作 之前使用的system.out.println()就属于Sys...

  • System类

    System 系统类:主要的作用是用于获取系统的一些参数。 需要掌握的方法: 控制台输出

  • System类

    String javaVersion = System.getProperty("java.version"); ...

  • System类

    System类System类常见方法和案例 exit退出当前程序 arraycopy:复制数组元素,比较适合底层调...

  • java-System & Runtime

    System类 System类介绍   System类代表Java程序运行平台,程序不能创建该对象,但是Syste...

  • System类方法currentTimeMillis exit

    08System类方法currentTimeMillis A:System类方法currentTimeMillis...

  • java lang包下的system类

    system 类 System 类包含一些有用的类字段和方法。它不能被实例化。 在 System 类提供的设施中,...

  • 2020-08-24--Java--day01【常用API】

    主要内容 System类 StringBuilder类 包装类 1.System类 java.lang.Syste...

网友评论

      本文标题:System类

      本文链接:https://www.haomeiwen.com/subject/hbpyactx.html