一.Runtime类
Java.lang.Runtime类封装了运行时的环境。
Runtime类一般不能实例化一个对象,例如:
Runtime r=new Runtime.getRuntime();
//这种方法是错误的,因为不能实例化对象。
//正确的方法是:
Runtime r=Runtime.getRuntime();
常用方法:
1.gc()方法
该方法运行垃圾回收器;
调用方法:Runtime.getRuntime().gc()
2.totalMemory()方法
返回java虚拟机中的内存总量;
3.freeMemory()方法
返回java虚拟机中的空闲内存量;
4.maxMomery()方法
返回java虚拟机中的试图使用的最大内存量;(内存无限制,则返回Long_MAX_VALUE)
5.exec()方法
可以用此方法在java中执行其他的程序。
exec()方法返回一个Process对象,可以用Process对象控制java程序和进程。
exec()方法格式:
//声明一个对象
Process p=Runtime.getRuntime().exec("String command")//里面填需要运行程序的路径。
Process p=Runtime.getRuntime().exec("String command","String envp[]",File dir)
Process p=Runtime.getRuntime().exec("String cmdarray[]","String envp[]")
Process p=Runtime.getRuntime().exec("String cmdarray[]")
Process p=Runtime.getRuntime().exec("String cmdarray[]","String envp[]",File dir)
Process p=Runtime.getRuntime().exec("String cmd","String envp[]")
上方通过exec()方法来创建一个可执行程序,而Process则负责控制该程序。
上述方法创建的可执行程序操作方法分别有:
p.destory();//杀掉子进程
p.exitValue();//返回子进程的出口值
p.getErrorStream();//获取子进程的错误流
p.getInputStream();//获取子进程的输入流
p.getOutputStream();//获取子进程的输出流
二.Object类
每个类都是Object的子类,可以使用类型为Object的变量指向任意类型的对象。
三.Math类
静态属性:E和PI
使用方法:Math.E Math.PI
方法:abs() //绝对值
pow(a,b) //a^b
max() //求最大值
min() //求最小值
random() //随机从0~1取浮点数
四.BigInteger类和BigDecimal类
BigInteger类和BigDecimal类分别表示大整数和大浮点类。
BigInteger(int numBits, Random rnd)
构造一个随机生成的BigInteger,均匀分布在0到(2 numBits - 1)的范围内。
BigInteger(String val)
将BigInteger的十进制字符串表示形式转换为BigInteger。
BigInteger(String val, int radix)
将指定基数中的BigInteger的String表示形式转换为BigInteger。
方法·:
1.add()
public BigInteger add(BigInteger val)返回值为 (this + val) 。
参数
val - 要添加到此BigInteger的值。
结果
this + val
2.subtract()
public BigInteger subtract(BigInteger val)返回值为 (this - val) 。
参数
val - 要从此BigInteger中减去的值。
结果
this - val
3.multiply()
public BigInteger multiply(BigInteger val)返回值为 (this * val) 。
参数
val - 要乘以此BigInteger的值。
结果
this * val
4.divide()
public BigInteger divide(BigInteger val)返回值为 (this / val) 。
参数
val - 这个BigInteger将被划分的值。
结果
this / val
异常
ArithmeticException - 如果 val为零。
五.Comparable接口
public interface Comparable<T>
该接口对实现它的每个类的对象强加一个整体排序。 这个排序被称为类的自然排序 ,类的compareTo方法被称为其自然比较方法 。
Collections.sort 和Arrays.sort可以自动对实现此接口的对象进行列表(和数组)排序。 实现该接口的对象,可以使用如在键sorted map或作为在元件sorted set ,而不需要指定一个comparator 。