对整书的概要。
略读。
其中boolean类型所占存储空间的大小没有明确指定,仅定义为能够取字面值true或false。
Integer类举例:
Integer i1 = 10;//this is autoboxing Integer i2 = 10; Integer i3 = 20; Integer i4 = new Integer(10); Integer i5 = new Integer(10); Integer i6 = new Integer(20); System.out.println(i1 == i2);//true (1) System.out.println(i3 == i1 + i2);//true (2) System.out.println(i1 == i4);//false (3) System.out.println(i4 == i5);//false (4) System.out.println(i6 == i4 + i5);//true (5) System.out.println(20 == i4 + i5);//true (6)
“+”操作符不适用于Integer对象,首先i4和i5先进行自动拆箱操作,得到20,然后i6也进行自动拆箱为int值20,相等
String s1 = "hello"; String s2 = "hello"; String s3 = "hel" + "lo"; String s4 = "hel" + new String("lo"); String s5 = new String("hello"); String s6 = s5.intern(); String s7 = "h"; String s8 = "ello"; String s9 = s7 + s8; System.out.println(s1 == s2);//true (1) System.out.println(s1 == s3);//true (2) System.out.println(s1 == s4);//false (3) System.out.println(s1 == s9);//false (4) System.out.println(s4 == s5);//false (5) System.out.println(s1 == s6);//true (6)
String string = "Hello"; string += "world";//string = "Hello world"
string += "world"并没有改变string所指向的对象,只是使得string指向了另外一个String类型的对象,原来那个字符串常量“Hello”还存在于内存中,并没有被改变
在Java语言中,原始数据类型在传递参数时都是按值传递,而包装类型在传递参数时是按引用传递的
8种基本数据类型用的是值传递,其他所有数据类型都是用的引用传递,由于这8种基本数据类型的包装类都是不可变类,引用传递并不会改变它的值
Integer a = 1; Integer b = a; b++; System.out.println("a = "+ a + "b = " + b);//a = 1, b = 2
由于Integer类是不可变类,因此没有方法提供改变它的值的方法;在执行完b++后,会创建一个新值为2的Integer赋值给b
int f[] = new int[10]; for (int x : f) System.out.println(x);
类的每个基本类型数据成员都会有一个初始值,对象引用会被默认初始化为null、可以通过构造器和其他方式进行初始化,但是不会影响默认初始化过程。
数组有一个固有成员length,是只读的,不可改变
Arrays.toString()方法会产生一维数组的可打印版本
原文:https://www.cnblogs.com/mcq1999/p/12026549.html