David said:
2 definitions:
String str1=null;
String str2="";
what's the deference??
i use the first definition, and then give str1 a value: str1="myName";
however, when i send this string from server to client, it displays:
nullmyName.
Like you're likely to hear from 100 others, str1 is a null reference (think
/pointer to no object/) and str2 is a reference to an empty string.
But as you learn about strings, you're gonna come face to face with another
issue. Because strings are immutable (once created, you cannot change them
in /any/ way, neither length nor content), the compiler is free (and
required) to share data whenever possible. Odd? Not really, here:
String str1 = "hello";
String str2 = "hello";
Both of these references point to the /exact/ same string. Same 1 object!
The compiler shared the data between them. That means that
(str1 == str2) is true ...and...
str1.equals(str2) is true
This can get confusing for a newbie (sorry if you aren't one). Take for
example the following:
String str1 = "hello";
String str2 = "hell";
str2 += "o";
They are two /different/ strings, both containing the same value. So:
(str1 == str2) is false ...and...
str1.equals(str2) is true
Sorry if this explanation was beneath you: it seemed like something worth
saying.