X32专项练习部分12
- 4种引用类型
- 线程锁释放
- for循环执行顺序
- Integer类的常用方法
- 三角函数
- GC垃圾回收机制
- 值传递开辟内存空间
- Java创建对象的5种方式
- 总目录
4种引用类型
线程锁释放
for循环执行顺序
class Test4 {
static boolean foo(char c) {
System.out.print(c); // ABDCBDCB
return true;
}
public static void main(String[] args) {
int i = 0;
for (foo('A'); foo('B') && (i < 2); foo('C')) {
i++;
foo('D');
}
}
}
Integer类的常用方法
public static void main(String[] args) {
int a = Integer.parseInt("1024");
int b = Integer.valueOf("1024").intValue();
System.out.println(judgeTypeInteger(a)); // true
System.out.println(judgeTypeInteger(b)); // true
System.out.println(a == b); // true
}
三角函数
double d = Math.cos(42);
// double d1 = Math.cosine(42); // cosine方法不存在
double d2 = Math.cos(Math.toRadians(42));
double d3 = Math.cos(Math.toDegrees(42));
System.out.println(d + " " + d2 + " " + d3);
// -0.39998531498835127 0.7431448254773942 0.9993069281930212
// 科学计算器算出的结果是 0.74314482547739423501469704897426
GC垃圾回收机制
值传递开辟内存空间
class Test7 {
public static void main(String[] args) {
int x1 = 127;
int x2 = 129;
int identityHashCode = System.identityHashCode(x1);
System.out.println("传递之前:x1 identityHashCode = "+identityHashCode);
identityHashCode = System.identityHashCode(x2);
System.out.println("传递之前:x2 identityHashCode = "+identityHashCode);
System.out.println("-----------------------------------------");
method(x1);
method(x2);
}
public static void method(int x) {
int identityHashCode = System.identityHashCode(x);
System.out.println("传递之后:x identityHashCode = "+identityHashCode);
}
}
Java创建对象的5种方式
总目录