Ragu,
compareTo works as follows:
this string and the parameter string are lexicographically compared, i.e. we take the index of the first character being different in both string.
Here "aha" and "aba" the first different character index is 1.
Then, the following number is returned
"aha".charAt(1) - "aba".charAt(1) => 'h' - 'b' => 104 - 98 = 6
If no index is found (i.e. -1) then the different of the length of the string is returned
"aha".length() - "".length() => 3 - 0 => 3
When a String is interned that String will be available in the String pool of the class. When you request the same String you just receive a reference to that String from the pool and not a new String object.
HIH
------------------
Valentin Crettaz
Sun Certified Programmer for
Java 2 Platform