Hi PETER,
1. Unless u override the equals() method, it will just compares the object references. here in SOP(System.out.println) the Object class' equals() method is called. As u r creating new 2 references, it will compare the BITS(internal representation , nothing but address(long integer)). So they are differnt.It will result in false.
2. When u call String s1 = "amit"; it will internally calls like this,
String s1= new String("amit");
JVM's String handling is like that, while creating Strings, for OPTIMIZATION, it will point the 2 references to the same object whose contents are same.But in S2==S3 case, this is somewhat different, as you are calling replace()method, The String.replace method will create a new object, As I think at this stage it wont look for optimization.
Correct me If I am Wrong,
Regards,
Nandish