关于Java的System,Integer,Math的自学心得
1 System类:
System类不能被实例化。它提供的工具包包括标准输入流,标准输出流和错误输出流;访问外部定义的属性和环境变量;加载文件和库的方法;快速复制数组一部分的实用方法。
字段(不太理解,看到别人说可以把它理解成类中的成员常量或成员变量)
static PrintStream err 标准错误输出流
static InputStream in 标准输入流
static PrintStream out 标准输出流
方法:
修饰符和类型 方法
1 static void arraycopy(数组a, 下标,数组b, 下标, 个数)
将指定源数组中的数组从指定位置开始复制到目标数组的指定位置 例子:
public class yu1 {
public static void main(String[] args) {
int[] a= {0,1,2,3,4,5,6,7,8,9};
int[] b=new int[20];
System.arraycopy(a,3,b,3,6);
for(int i=0;i<20;i++)
{
System.out.println(b[i]);
}
}
}
2static String clearProperty(String key)
删除指定键指示的系统属性。
3static Console console()
返回Console与当前Java虚拟机关联的唯一对象(如果有)。
4static long currentTimeMillis()
以毫秒为单位返回当前时间。
5static void exit(int status)
终止当前运行的Java虚拟机。
6static void gc()
运行垃圾收集器。
(System还有很多的方法,这里只提到其中常见的几种,其它很多我不能理解它的用途)
2 Integer类:
该类主要是把转换成对象的数据进行其所需要的类型转换,以及进行相关操作。
字段
1 static int BYTES
用于表示int二进制补码二进制形式的值的字节数。
2 static int MAX_VALUE
保持最大值的常数int可以是2的 31次方 -1。
3 static int MIN_VALUE
保持最小值的常数int可以有-2的 31次方。
4 static int SIZE
用于表示int二进制补码二进制形式的值的位数。
5 static Class TYPE
Class表示基本类型的实例 int。
方法
1 static int bitCount(int i)
返回指定int值的二进制补码表示形式中的一位数
2 byte byteValue()
返回的这个值Integer作为byte 一个基本收缩转换后。
3 static int compare(int x, int y)
以int数字方式比较两个值。
4 static int compareUnsigned(int x, int y)
比较两个int值,以数值方式将值视为无符号。
5 int intvalue()
返回此值Integer作为 int;
例如:
public class yu1 {
public static void main(String[] args) {
String str = “10”;
Integer it = new Interger(str);
int i = it.intValue();
System.out.print(i);
}
}
3 Math类:
Math类包含执行基本数值运算的方法,如基本指数,对数,平方根和三角函数。
字段
1 static double E
double比任何其他值更接近e的值,即 自然对数的基数。
2 static double PI
的double是比任何其他更接近值 PI,圆其直径的圆周的比率。
方法:
1 static double abs(double a)
返回值的绝对值double。
2 static float abs(float a)
返回值的绝对值float。
3 static int abs(int a)
返回值的绝对值int。
4 static long abs(long a)
返回值的绝对值long。
5 static double acos(double a)
返回值的反余弦值; 返回的角度在0.0到pi的范围内。
(asin 为反正弦;atan 为反正切)
6 static double atan2(double x,double y)
返回直角坐标转换的极坐标
7 max,min可以返回两个值(同一数据类型)之间的最大值,最小值。例如:
public class yu1 {
public static void main(String[] args) {
int a=5;
int b=9;
int c=Math.max(a,b);
System.out.print©;
}
}