天天看点

黑马程序员_System类、Runtime类学习笔记

---------------------- <a href="http://www.itheima.com" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="blank">ASP.Net+Unity开发</a>、<a href="http://www.itheima.com" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="blank">.Net培训</a>、期待与您交流! ----------------------

1.System类

一、功能与用途

System类是jvm启动时加载和操作系统相关的默认信息并以键值对的形式放到map中。

二、特点

1.它是用final修饰类,所以不能被继承。

2.它对外没有提供构造器类,所以只能使用static关键字,调用类成员属性和行为。

三、常用属性和方法

(1)常用属性

System.in    标准输入流,即键盘录入的值。

System.out 标准输出流,即console控制台。

(2)常用方法

gc(), 系统运行时垃圾回收器。

currentTimeMillis() ,系统当前时间,单位:毫秒。

getProperties(),返回Properties对象,Properties又是HashTable的子类,所以系统相关信息是键值对的形式存储到Properties对象中。

getProperty(String key),通过key或者系统的值,如getProperty(“os.name”)操作系统名称。

setProperties(Properties props),设置Properties对象。

setProperty(String key,String value) ,用实际键和值来设置系统信息。

2.Runtime类

它是Java运行时环境对象,每一个Java应用程序都有一个运行时环境。即一个Runtime实例,在这类中无对外可访问的构造函数,但提供了可获得该类对象的方法getRuntime()且为静态的,说明它是单例模式的典型应用。

该类中常用的方法说明:

getRuntime(),获得一个Runtime对象,对于每个Java应用程序有且仅有一个。

gc(),垃圾回收器,通常由jvm自动调用,不需要程序员考虑。

exec(String command),操作系统中console界面执行的命令。

---------------------- <a href="http://www.itheima.com" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="blank">ASP.Net+Unity开发</a>、<a href="http://www.itheima.com" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="blank">.Net培训</a>、期待与您交流! ----------------------

详细请查看:<a href="http://www.itheima.com" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="blank">www.itheima.com</a>