ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
Do you have a collection of Interview Questions and interested to share with us!!
Please send that collection to along with your userid / name. ThanQ
Google
 
Categories  >>  Software  >>  Core Java  >>  Java J2EE  >>  Java Related
 
 


 

 
 Core Java interview questions  Core Java Interview Questions
 Advanced Java interview questions  Advanced Java Interview Questions
 Swing interview questions  Swing Interview Questions
 EJB interview questions  EJB Interview Questions
 Servlets interview questions  Servlets Interview Questions
 Struts interview questions  Struts Interview Questions
 JDBC interview questions  JDBC Interview Questions
 JMS interview questions  JMS Interview Questions
 SunOne interview questions  SunOne Interview Questions
 J2EE interview questions  J2EE Interview Questions
 Weblogic interview questions  Weblogic Interview Questions
 Websphere interview questions  Websphere Interview Questions
 Java Networking interview questions  Java Networking Interview Questions
 Java J2EE AllOther interview questions  Java J2EE AllOther Interview Questions
Question
where is .equals() method and how is it different from == 
operation <giving some confusing implementation> Is hashing 
related to these?
 Question Submitted By :: Esha Prasad
I also faced this Question!!     Rank Answer Posted By  
 
  Re: where is .equals() method and how is it different from == operation <giving some confusing implementation> Is hashing related to these?
Answer
# 1
.equlas() method is in Object class which compares two 
objects and returns true if both are same.

== compares whether two references  pointing to same memory 
location.
 
Is This Answer Correct ?    1 Yes 0 No
Esha Prasad
 
  Re: where is .equals() method and how is it different from == operation <giving some confusing implementation> Is hashing related to these?
Answer
# 2
== operator return true if both reference variable pointing 
to same object.
equals() method also use == as default, but String and 
Wrapper classes override (you can also override) it but 
meaningfull comparison , as in two same String case it 
returns true for equals()method.

for knowing it clearly make small programs by using both. 
there are so many exception  in wrapper classes.
 
Is This Answer Correct ?    0 Yes 0 No
Tanuj
 
 
 
  Re: where is .equals() method and how is it different from == operation <giving some confusing implementation> Is hashing related to these?
Answer
# 3
equals() method is used for comparison. it copares the 
content whereas == is used to compare the references. 

if the hashcode value is same for two objects equals() 
method will return true. but in case of == it is not the 
case.

Try following code 

String str="Java";
String str1="Ja";
String str2="va";
String str3=str1+str2;
String str4 = new String("Java");
String str5 = str4;
String str6 = new String("Programming");
String str7 = new String(str6);
System.out.println(str3);
System.out.println("str "+str.hashCode());

System.out.println("str3 :- "+str3.hashCode());
System.out.println("str4 :- "+str4.hashCode());
System.out.println("str5 :- "+str5.hashCode());
System.out.println("str6 :- "+str4.hashCode());
System.out.println("str7 :- "+str5.hashCode());


if(str==str3)
	System.out.println("str and str3 are equal(==)");
else
	System.out.println("str and str3 are not equals
(==)");
if(str.equals(str3))
	System.out.println("str and str3 are equals(.equals
())");
else
	System.out.println("str and str3 are not equals
(.equals())");


if(str4==str5)
	System.out.println("str4 and str5 are equal(==)");
else
	System.out.println("str4 and str5 are not equals
(==)");
if(str.equals(str3))
	System.out.println("equals");
else
	System.out.println("not equals");


if(str6==str7)
	System.out.println("str6 and str7 are equal(==)");
else
	System.out.println("str6 and str7 are not equals
(==)");
if(str.equals(str3))
	System.out.println("equals");
else
	System.out.println("not equals");
 
Is This Answer Correct ?    0 Yes 0 No
Namita
 

 
 
 
Other Core Java Interview Questions
 
  Question Asked @ Answers
 
To what value is a variable of the Boolean type automatically initialized?  3
why java does not support multiple inheritance Mind-Tree8
which one is performance wise advantageious from List,Set,Map?  4
To obtain design information about an object, which class in used?  1
What are interfaces?  1
What modifiers are used for interface declaration?  2
Can you call a private data from an inner class?  3
What is the Dictionary class?  1
what do you meant by Runtime Polymorphism? Persistent9
explain the classification of exception and hoew to handle the exceptions  2
Difference between Reader/Writer and InputStream/Output Stream? Kirusa3
Differences between GridLayout and GridBagLayout?  1
What is the differenc between Enemuration interface and iterator interface according to accessing?  4
What is update method and when it is called?  1
What modifiers are used with an inner class which is a member of an outerclass?  1
Can you have an inner class inside a method and what variables can you access?  1
How to prevent a field from serialization ?  2
Which class is extended by all other classes?  2
when i write string s1="java"; in one program(application) and string s2="java"; in another application on the same jvm will both objects s2,s2 will refer to same memory location where "java" is stored in string pool.  1
They had given one progam final HashMap hm=new HashMap(); public void show() { hm.put("name",value); } in this prg here the final hashtable value can be changed in put method,its the prg run? DNS2
 
For more Core Java Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com