1- String objects pool issue
String object is immutable; thats mean when you say
String s = "Mohammed";
s += "El-Adawi";
on runtime this means that a new String "Mohammed El-adawi" is created
and assigned to reference s
and String "Mohammed" now is eligable for gc
why sun have to do that ?, because String literals
(any thing between " " is reccognized by compiler as String literal)
are put by compiler in String pool, then if compilar found the same literal again for example
String s = "abc";
String m = "abc";
compiler will have one copy of "abc" and will assign both s,m to the same String literal, (at run time one object constructed and asigned to s,m)
if m change the String, s will point to the wrong thing, thats why String is immutable.
2- answer to your question
String s = "Marcus";
String s2 = new String("Marcus");
String s3 = new String("Mohammed Not Marcus");
3- Another thing
String s1 = "abc";
String s2 = "abc";
System.out.println(s1 == s2);
but
String s1 = "abc";
String s2 = new String ("abc");
System.out.println(s1 == s2);
I hope that is helpfull