Pages

strings quns

Q) What is hash code?

A)    It is a unique identification number that is allotted by JVM to the objects. This number is also called reference number.


So the out put is not same. == is only compare reference numbers
In the above program correct format is if(s1.equals(s2))

Q) What is the difference between == to and equals method while comparing the strings?
A) == operator compares only the reference of string objects.
Equals method compares the contents of the string objects. Hence the equals’ method gives reliable results.
Q) What is string constant pool?
A) It is separate block of memory where the string objects are stored.


If(s1==s2)
o/p:   equal, because JVM does not waste memory.

Q) What is the difference between the following statements?
          a) String s=”Hello”;
          b) String s=new String(“Hello”);