//计算一个程序执行时间
package org.sys;
public class SystemDemo01 {
public static void main(String[] args) {
long startTime = System.currentTimeMillis();
int sum = 0;
for(int i = 0;i<30000000;i++){
sum += sum;
}
long endTime = System.currentTimeMillis();
System.out.println("计算所花费的时间:"+(endTime-startTime)+"毫秒。");
}
}
//取得本机的全部环境属性
package org.sys;
public class SystemDemo02 {
public static void main(String[] args) {
System.getProperties().list(System.out);
}
}
//列出指定属性
package org.sys;
public class SystemDemo03 {
public static void main(String[] args) {
System.out.println("系统版本为:"+System.getProperty("os.name")
+System.getProperty("os.version")
+System.getProperty("os.arch"));
System.out.println("系统用户为:"+System.getProperty("user.name"));
System.out.println("当前用户目录:"+System.getProperty("user.home"));
System.out.println("当前用户工作目录:"+System.getProperty("user.dir"));
}
}
//垃圾对象的回收
package org.sys;
package org.sys;
class Person {
private String name;
private int age;
public Person(String name, int age) {
super();
this.name = name;
this.age = age;
}
public String toString(){
return "姓名:"+this.name+",年龄"+this.age;
}
@Override
protected void finalize() throws Throwable {
// TODO 自动生成的方法存根
System.out.println("对象被释放-->"+this);
}
}
public class SystemDemo04 {
public static void main(String[] args) {
Person per = new Person("陈飞鹏",22);
per = null;
System.gc();
}
}