[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]
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]