j2se-----System和Runtime

[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]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值