class StringEqual
{
public static void main(
String args[])
{
String s1="JavaServerPages";
String s2="JavaServer"+"Pages"; //Line 1
String s3="Pages";
String s4="JavaServer"+s3; //Line 2
if (s1==s2)
System.out.println ("s1 and s2 are equal");
else
System.out.println ("s1 and s2 are not equal");
if (s1==s4)
System.out.println ("s1 and s4 are equal");
else
System.out.println ("s1 and s4 are not equal");
}
}
output
s1 and s2 are equal
s1 and s4 are not equal
What does JVM do in line 1 and line. Could any one explain me
Raghu J<br />SCJP 1.4<br /> <br />The Wind and waters are always<br />on the side of the ablest navigators.<br /><a href="http://groups.yahoo.com/group/scjp_share" target="_blank" rel="nofollow">SCJP Group</a><br /><a href="http://groups.yahoo.com/group/JavaBeat_SCWCD" target="_blank" rel="nofollow">SCWCD Group</a>