System类
获取毫秒:System.currentTimeMillis();
获取纳秒:System.nanoTime();
拷贝数组:System.arraycopy(原数组, 从什么位置开始拷贝, 新数组, 新数组开始拷贝位置, 长度);
手动调用垃圾回收机制:System.gc();
获取分隔符:System.lineSeparator();
终止程序退出jvm:System.lineSeparator()。
package com.openlab.day16.main;
public class TestSystem {
public static void main(String[] args) {
// System.out.println(new Date().getTime());
// 毫秒
System.out.println(System.currentTimeMillis());
// 纳秒
System.out.println(System.nanoTime());
// System.arraycopy(原数组, 从什么位置开始拷贝, 新数组, 新数组开始拷贝位置, 长度);
// 手动使用gc
System.gc();
System.out.println(System.lineSeparator());
// 终止程序,JVM退出
System.exit(0);
}
}
Runtime类
Runtime类不能实例化,只能通过单例模式获取对象,即下列代码:Runtime runtime = Runtime.getRuntime();
package com.openlab.day16.main;
public class TestRuntim {
public static void main(String[] args) throws Exception {
Runtime runtime = Runtime.getRuntime();//单例模式
// 返回当前运行时的JVM中运行的java进程
System.out.println(runtime.availableProcessors());
// JVM内存使用情况
System.out.println(runtime.freeMemory());
System.out.println(runtime.maxMemory());
System.out.println(runtime.totalMemory());
// System调用的退出系统、gc等方法,实质是Runtime中方法
runtime.exec("calc");//打开计算器
// runtime.exec("cls");//清屏
runtime.exec("notepad");//打开记事本
runtime.exec("mspaint");//打开画板
runtime.exec("ipconfig");//获取ip地址
}
}
运行结果: