[code]
System類是與系統相關的重要函數
System.exit(0);//正常退出虛拟機
System.currentTimeMills();
System.getProperties()和System.setProperties();//分别用于設定或擷取JVM的系統屬性
System.getProperties().list(System.out);//列印全部系統屬性
System.gc();//垃圾回收
對象生命周期:
初始化--->
對象執行個體化--->垃圾收集--->對象終結
---->解除安裝
class Person{
private String name;
private int age;
public Person(String name,int age){
this.name=name;
this.age=age;
}
public String toString(){
return "姓名:"+this.name+",年齡:"+this.age;
}
public void finalize() throws Throwable{ //這個方法在垃圾回收時候自動調用
System.out.println("對象被回收了");
}
}
publci class Test{
public static void main(String[] args){
Person per = new Person("張三",30);
per = null;
System.gc(); //強制性釋放空間
}
}
Runtime類封裝了java指令本身啟動的執行個體程序,也就是封裝了JVM程序。。一個java虛拟機對應一個Runtime執行個體對象,是以一個JVM也就隻有一個Runtime執行個體,當然Runtime中的許多方法和System中的方法相重複
Rumtime.getRuntime()得到執行個體對象的引用,因為JVM是作業系統的一個程序,那麼由他啟動的其他程序叫做它的子程序
1.例如:啟動記事本程式,打開 aa.java,然後5秒後關閉
Process p = Runtime.getRuntime().exec("notepad.exe aa.java");
Thread.sleep(5000);
p.destory();
[/code]