- Math:
//abs表示返回绝对值
/*System.out.println(Math.abs(-88));
//ceil表示向上取整,向正无穷方向获取最近的整数
System.out.println(Math.ceil(11.1));
//floor表示向下取整,相当于去尾,向负无穷方向获取最近的整数
System.out.println(Math.floor(2.2));
//round表示四舍五入
System.out.println(Math.round(-12.54));//13
//Max表示获取两个数之间的最大值
System.out.println(Math.max(3, 5));
//Min表示获取两个数之间的最小值
System.out.println(Math.min(3, 5));
//pow获取a的b次幂
System.out.println(Math.pow(2, 3));
//sqrt表示开平方根
System.out.println(Math.sqrt(4));
//cbrt表示开立方根
System.out.println(Math.cbrt(8));
//random()获取一个double类型的随机数,范围是[0.0,1)
System.out.println(Math.round(2));
*/
- System:
//方法形参是一个状态码
//0表示正常停止,非0表示异常停止
// java.lang.System.exit(0);
//System.currentTimeMillis();表示返回系统的时间毫秒值形式
//long l = java.lang.System.currentTimeMillis();
//System.out.println(l);
/*System.arraycopy拷贝数组
参数一;数据源,表示要拷贝的数组来自哪里
参数二:从数据源数组中的第几个索引开始拷贝
参数三;目的地数组,我要把数据拷贝到哪个数组中
参数四:目的地数组的索引
参数5:拷贝的个数*/
int[] array1= {1,2,3,4,56,7,8,9,10};
int[] array2 =new int[10];
java.lang.System.arraycopy(array1,0,array2,0,array1.length);
- Runtime:
//1:获取Runtime对象
//Runtime runtime = Runtime.getRuntime();
//2:exit关闭虚拟机
//Runtime.getRuntime().exit(0);
//3:获取CPU线程数
/* System.out.println(Runtime.getRuntime().availableProcessors());
//总内存大小,单位是byte
System.out.println(Runtime.getRuntime().maxMemory());
//已经获取的总内存大小,单位是byte
System.out.println(Runtime.getRuntime().totalMemory());
//剩余内存的大小
System.out.println(Runtime.getRuntime().freeMemory());
//运行cmd命令
//shutdown关机,需要加上参数
//-s默认在一分钟后关机
//-s -t 加时间:指定关机时间
//-a取消关机操作
//-r关机并重启
Runtime.getRuntime().exec("notepad");
// Runtime.getRuntime().exec("shutdown -s -t 1200")*/
- object:
//1:toString()返回对象的字符串表示形式
Object object=new Object();
String s = object.toString();
System.out.println(s);//java.lang.Object@1b6d3586
Student student = new Student();
String s1 = student.toString();
System.out.println(s1);//API.Student@4554617c
/*细节1:
System:类名
out:静态变量
System.out:获取打印的对象
println():方法,方法中的参数表示打印的内容
核心逻辑:
当我们打印一个对象的时候,最底层会去调用toString()方法,把对象变成字符串,然后在控制台打印出来,最后换行
细节2:
toString()的方法结论:
当我们想看到打印一个对象时,如果想看到属性值,那么就重写toString()方法,在重写的方法中,把对象的属性值进行拼接,因为所有类都继承object类
System.out.println(s1);
*/
//public boolean equals(Object obj) 比较两个对象是否相等
Student student1= new Student(2,"2");
Student student2 = new Student(2,"2");
System.out.println(student1.equals(student2));//每次创建一个对象,地址值都不一样
/*
equals小结:
1:如果没有重写equals方法,那么将默认调用object中的方法,比较的是地址值是否相等
2:一般来说地址值对于我们的意义不大,所以我们会重写,重写之后比较的就是对象内部的属性值,
*/