e文也不好,只能回答第三题:
public class Test { public static void main(String[] args) {
String a = "a";
String b = new String("a");
if (a == b) {
System.out.println("equals");
} else {
System.out.println("not equals");
}
}
}
这种情况下a的值等于b,但是a==b为false。
public class Test { public static void main(String[] args) {
String a = "a";
String b = new String("a");
if (a == b) {
System.out.println("equals");
} else {
System.out.println("not equals");
}
}
}
这种情况下a的值等于b,但是a==b为false。
java写的程序也会导致内存泄漏3.有可能相等也有可能不相等 s1 = "aaa"
s2 = "aaa" 则 s1 == s1,因为s1和s2引用同一个对象
通过System.identityHashCode()可以看出 String s3 = new String("aaa") s1 != s3 因为s3和s1引用的不是一个对象
4.Serializable
5.运行时异常之外的exception都能被catch住吧
2,不能保证,可能会gc来不及回收的情况
3,比如:String str1="aa";
String str2=new String("aa");
String str3=new String("aa");
System.out.println(str1==str2);
System.out.println(str1==str3);
System.out.println(str3==str2);
这三种两两不等
注意:只要是new String();肯定是得到一个新的String对象,在heap上分配内存,这与编译器常量(“aa”)是不同的
4,java.io.Serializable
5,Error类 这种异常不可捕捉,Exception的子类均可catch,RuntimeException也可catch
2. can not guarantee
3. String a="aa";
String b=new String("aa");
String c=new String(a);
In this two situations that mentioned above, the value of two string objects with identical values not to be equal under the == operator. So, there is only use "new" to declare a string, the values are not equal under the operator ==, even the value of these two veriables are exactly same.
4. java.io.Serializable
5. class Error