System对象
常用的方法
System.gc();垃圾回收器
System.getProperties() ; 得到Properties对象,继承自HashTable();
Properties获取系统的属性的常用信息,Properties pop = System.getProperties();
通过Properties得到系统的所有的属性
Set set = pop.KeySet();
for(Object object :Set set){
String key = (String)object;
String value= pop.get(key);
}
得到你知道的系统key的话,可以直接取得value的值
String value=pop.getProperty(key);
想加添加系统级信息的话
pop.setProperty();
虚拟机启动的时候动态加载信息
java -Dkey=value
System.in();获取键盘输入的信息 返回值为InpuStream
使用方法
Scanner scanner = new Scanner(System.in());
scanner.next();得到键盘输入的值
获取键盘输入以空格为分号符
System.out();将信息打印到控制台 返回值为PrintStream;
使用方法
System.out.print("“);
RunTime对象
Runtime.getRuntime(); 因为Runtime无构造函数, 是单例模式通过getRuntime(); 获取实例
常用方法
Runtime runtime=Runtime.getRuntime();
runtime.exec("shutdown /s /t 1000");
可以执行cmd命令
还可以用某个软件打开某个文件
runtime.exec("notepad aa.txt");
Date对象
Date date = new Date(); 获取系统时间
由于时间格式看的不太习惯所以要对时间进行格式化,成为我们想要的格式
DateFormat df = new SimpleDateFormat(“yyyy-MM-dd”); 也可以通过
df.format(date);
另外一种Caleder格式化方法
Calendar calendar = Calendar.getInstance();
calendar.get(YEAR);取得年 返回值为int
calendar.add(年,+1);为给定的日历字段添加或减去指定的时间量
使用环境
常用于计算某个月有多少天,知道当月的第一天,下月的第一天,
然后下个朋的第一天减去1就是当月的最后一天,最后一天减第一天就是这个月的天数
Math对象
Math.round(); 对某个数进行四舍五入
Math.pow();返回某个数的次幂值 如Math.pow(4,2)=16;
Math.ceil(16.1),返回大于参数的最小整数
Math.floor(16.1),返回小于参数的最大整数
Math.random();最得某个值的的随机数 0.0-1.0
也可以用Random.nextInt(值)来得到某个值的随机数