"Dont"+"cry" is evaluated at compile time to "Dontcry" which is already in the strings-literals pool, while (s + "cry") is evaluated at runtime and the result is a new string stored in the heap (not in the pool), so s3 and d4 will refer to different objects.
If you mean why the compiler doesn't evaluate it at copmile time, consider a more general case where s is not local to the method: how can the compiler garantee that s doesn't change?
System.identityHashCode() method return the same hashcode an object would have been given by the default Object.hashCode() method. And because the default hashCode() method is it's memory address expressed as an int, you will directly see if references are pointing to the same memory location.
Hope it can help you.
Vincent Brabant<br /><a href="http://fr.netbeans.org" target="_blank" rel="nofollow">http://fr.netbeans.org</a>