1.System类
public void test1() {
String javaVersion = System.getProperty("java.version");
System.out.println("java的version:" + javaVersion);
String javaHome = System.getProperty("java.home");
System.out.println("java的home:" + javaHome);
String osName = System.getProperty("os.name");
System.out.println("os的name:" + osName);
String osVersion = System.getProperty("os.version");
System.out.println("os的version:" + osVersion);
String userName = System.getProperty("user.name");
System.out.println("user的name:" + userName);
String userHome = System.getProperty("user.home");
System.out.println("user的home:" + userHome);
String userDir = System.getProperty("user.dir");
System.out.println("user的dir:" + userDir);
}
2.Math类
3.BigInteger类、BigDecimal类
说明:
代码举例:
// 一般的Float类和Double类可以用来做科学计算或工程计算,
// 但在商业计算中, 要求数字精度比较高,故用到java.math.BigDecimal类。
// BigDecimal类支持不可变的、任意精度的有符号十进制定点数
@Test
public void test2() {
BigInteger bi = new BigInteger("1243324112234324324325235245346567657653");
BigDecimal bd = new BigDecimal("12435.351");
BigDecimal bd2 = new BigDecimal("11");
System.out.println(bi);
// System.out.println(bd.divide(bd2));
System.out.println(bd.divide(bd2, BigDecimal.ROUND_HALF_UP));//保留默认的小数
System.out.println(bd.divide(bd2, 25, BigDecimal.ROUND_HALF_UP));//保留25位小数
}
4.Runtime类
package com.epoint.classPractice;
import java.io.IOException;
public class TestRunTime {
public static void main(String[] args) {
Runtime rt = Runtime.getRuntime();
rt.availableProcessors();
rt.freeMemory();
rt.totalMemory();
rt.maxMemory();
try {
//windows下的exe可以直接运行
rt.exec("notepad.exe");
//执行其它目录下的程序
//rt.exec("D:\\xx.exe");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
结果:
执行以上程序会打开记事本