Question 1
String a1 = \"I Love\" + \" Java\";
String a2 = \"I Love \" + \"Java\";
System.out.println( a1 == a2 ); // true
String b1 = \"I Love\";
b1 += \"
From intern() docs
All literal strings and string-valued constant expressions are interned. String literals are defined in section 3.10.5 of the The Java™ Language Specification.
And from JLS 3.10.5
- Strings computed by constant expressions (§15.28) are computed at compile time and then treated as if they were literals.
- Strings computed by concatenation at run time are newly created and therefore distinct.
Your string b1 not actually interned. Hence the difference.