目录
System
1.接口介绍:
System.exit() 终止当前运行的虚拟机
0:正常停止 非0:异常停止
System.currentTimeMillis()返回当前的系统时间,毫秒单位
返回当前系统的时间毫秒值形式,可以用来计算程序的运行时间
System.arraycopy() 数组拷贝
参数意义:数据源、数据源起始索引、目的地、目的地起始索引、拷贝数据长度 若拷贝的是基本数据类型,则类型需要一致 若拷贝的是引用数据类型,子类的可以拷贝给父类
2.代码
package Math_learning;
public class systemdemo1 {
public static void main(String[] args) {
//System.exit(0);//0:正常停止 非0:异常停止
long l=System.currentTimeMillis();//返回当前系统的时间毫秒值形式,可以用来计算程序的运行时间
System.out.println(l);
int []arr1={1,2,3,4,7,5,6};
int []arr2=new int [7];
//参数意义:数据源、数据源起始索引、目的地、目的地起始索引、拷贝数据长度
//若拷贝的是基本数据类型,则类型需要一致
//若拷贝的是引用数据类型,子类的可以拷贝给父类
System.arraycopy(arr1,0,arr2,0,5);
for (int i = 0; i < arr2.length; i++) {
System.out.println(arr2[i]);
}
Student s1=new Student(16,"xiaoming");
Student s2=new Student(17,"xaiohong");
Student s3=new Student(18,"xiaolan");
Student []arr3={s1,s2,s3};
Person []arr4=new Person[3];
System.arraycopy(arr3,0,arr4,0,3);
for (int i = 0; i < arr3.length; i++) {
System.out.println(arr4[i].age+" "+arr4[i].name);
}
}
}
class Person{
int age;
String name;
Person(int age,String name){
this.age=age;
this.name=name;
}
}
class Student extends Person{
Student(int age, String name) {
super(age, name);
}
}
Runtime
1.接口介绍:
Runtime.getRuntime() 当前系统运行的环境对象
exit() 停止虚拟机
availableProcessors()获得CPU放入线程数
maxMemory() JVM能从系统获取的总内存大小(byte)
totalMemory() JVM已经从系统中获取的总内存大小
freeMemory()JVM剩余内存大小
exec() 运行cmd命令
/*shutdown 关机 * -s 默认在一分钟内关机 * -s -t 指定关机时间 * -a 取消关机操作 * -r 关机并重启*/
2.代码
package Math_learning;
import java.io.IOException;
public class Runtimedemo1 {
public static void main(String[] args) throws IOException {
System.out.println(Runtime.getRuntime().availableProcessors());//获得CPU的线程数
System.out.println(Runtime.getRuntime().maxMemory());
System.out.println(Runtime.getRuntime().freeMemory());
//运行Cmd命令
/*shutdown 关机
* -s 默认在一分钟内关机
* -s -t 指定关机时间
* -a 取消关机操作
* -r 关机并重启*/
System.out.println(Runtime.getRuntime().exec("notepad"));//打开记事本
}
}