Java Programming
code - 1
{
String a = "ABC";
String b = "ABC";
boolean c = (a==b);
System.out.println("a == b? "+c);
}
code - 2
{
String a = new String("ABC");
String b = new String("ABC");
boolean c = (a==b);
System.out.println("a == b? "+c);
}
Why the output of code 1 and code 2 is differnce
[377 byte] By [
Java1a] at [2007-10-2 7:37:06]

The difference is that in c1 code, both the String Objects a and b refer to the same object instance i.e. "ABC". However, in c2 code, when you initialize them with new String() constructor, two different instances a and b of String are created. == operator compares the two object instances. If they refer to the same instance, it return true otherwise false. Is it clear?