RunTime是单例,可以用来测试总内存和剩余内存
public class Person {
String name;
int age;
public Person(String name, int age) {
this.name = name;
this.age = age;
}
@Override
public String toString() {
return "Person{" +
"name='" + name + '\'' +
", age=" + age +
'}';
}
}
public class RuntimeTest {
@Test
public void test01(){
//RunTime是单例
Runtime r1 = Runtime.getRuntime();
Runtime r2 = Runtime.getRuntime();
System.out.println("r1==r2 = " + (r1 == r2));
System.out.println("空闲内存 r1.freeMemory() = " + r1.freeMemory());
System.out.println("总内存 r1.totalMemory() = " + r1.totalMemory());
}
@Test
public void test02() {
Runtime r1 = Runtime.getRuntime();
System.out.println("r1.totalMemory() = " + r1.totalMemory());
System.out.println("r1.freeMemory() = " + r1.freeMemory());
for (int i = 0; i < 100000; i++) {
new Person("张三"+i, i);
}
//运行垃圾会收器
// System.gc();
System.out.println("r1.totalMemory() = " + r1.totalMemory());
System.out.println("r1.freeMemory() = " + r1.freeMemory());
}
}
System
public class SystemTest {
@Test
public void test04() {
System.out.println("1111");
//结束jvm
System.exit(0);
System.out.println("33333");
}
@Test
public void test03() {
String[] arr = {"安琪拉", "米莱迪", "亚索"};
String[] newArr = new String[4];// 将"米莱迪","亚索" 放到 newArr 下标 为 2 3的位置
String string = Arrays.toString(newArr);
System.out.println("string = " + string);
System.arraycopy(arr, 1, newArr, 2, 2);
String string1 = Arrays.toString(newArr);
System.out.println("string1 = " + string1);
}
@Test
public void test02() {
//获取jdk配置信息
Properties properties = System.getProperties();
//展现所有的配置信息
//输出流
properties.list(System.out);
String property = System.getProperty("java.version");
System.out.println("property = " + property);
}
@Test
public void test01() {
//获取当前时间的毫秒数
long currentTimeMillis = System.currentTimeMillis();
System.out.println("currentTimeMillis = " + currentTimeMillis);
}
}