| Other Core Java Interview Questions |
| |
| Question | Asked @ | Answers |
| |
| public class AboutStrings{
public static void main(String args[]){
String s1="hello";
String s2="hel";
String s3="lo";
String s4=s2+s3;
//to know the hash codes of s1,s4.
System.out.println(s1.hashCode());
System.out.println(s4.hashCode());
// these two s1 and s4 are having same hashcodes.
if(s1==s4){
System.out.println("s1 and s4 are same.");
}else
System.out.println("s1 and s4 are not same.");
}
}
Somebody told me that, == operator compares references of
the objects.
In the above example even though s1 and s4 are refering to
same object(having same hash codes),
it is printing s1 and s4 are not same.
Can anybody explain in detail why it is behaving like this?
Thanks in Advance
RavuriVinod
| TCS | 3 |
| whats the diff between jsp and servlets? | HCL | 8 |
| what Data encapsulation in java? | | 2 |
| What is the difference between pageContext and page
implicit objects in jsp? | Merrill-Lynch | 6 |
| Differentiate Vector and ArrayList? | Wipro | 3 |
| which one the better thread emplemented thread or extended ? | Fidelity | 3 |
| what is java | | 8 |
| Howmany classes that package java.applet.* contains? | TCS | 1 |
| What is Remote Interface ? | CTS | 2 |
| what are the purposes of native, transiant key words? | | 2 |
| Can an unreachable object become reachable again? | | 3 |
| how can u apply shallow cloning and deep cloning to create
object? | Yash-Technologies | 1 |
| Is it possible to create Userdefined Unchecked Exception
also?If Yes, give an example? | | 2 |
| Which of the following can be referenced by a variable?
A. The instance variables of a class only
B. The methods of a class only
C. The instance variables and methods of a class | | 1 |
| what is difference between method overloading & method
overridding with example? | IBM | 2 |
| What is a default package ? | | 4 |
| How 'java' got its name and what it stands for? | | 3 |
| What is adapter class? | | 2 |
| Can you declare a static variable in a method? | | 3 |
| what is difference between requestprocessor and request
dispatcher? | Tech-Mahindra | 1 |
| |
| For more Core Java Interview Questions Click Here |