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                      
tip       Ask Questions on ANYTHING, that arise in your Daily Life at     FORUM9.COM
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
what is the difference between equals method and ==
 Question Submitted By :: Guest
I also faced this Question!!     Rank Answer Posted By  
 
  Re: what is the difference between equals method and ==
Answer
# 1
equal method is used to check whether the two strings are 
equal(same). exmpl: if the 1st string is 'deva' then it ll 
check the 2nd is also 'deva'. whereas = is a assignment 
operator used to assign a value to the variable.
 
Is This Answer Correct ?    5 Yes 15 No
Thevendhiran.k
 
  Re: what is the difference between equals method and ==
Answer
# 2
== is userd to compare both are of same type 
equals is used to compare both are of same contents


EX:
String s1="raju";
String s2=new String("raju");
if(s1.equals(s2))
System.out.println(" if(s1.equals(s2)");  //true
if(s1==s2)
System.out.println(" s1==s2");   //false
 
Is This Answer Correct ?    20 Yes 3 No
Subrahmanyam
 
 
 
  Re: what is the difference between equals method and ==
Answer
# 3
== checks the reference value, that the reference are of 
same object or not.

equals method check two strings are same or not
 
Is This Answer Correct ?    10 Yes 1 No
Sandeep Arora
 
  Re: what is the difference between equals method and ==
Answer
# 4
equals() method is from Object Class.So this is the method
 to check the equality between two objects.This method 
implements the equalence relation.

ex obj1     o1  = "ravi";
   obj2     o2  = "ravi";

   o1.equals(o2) ;// returns true.

== Operator. no doubt this is the operator. It can be used 
in two ways
1:To compare the values of primitive variables.
2.To compare the object refference variables.
it returns true if refference variable reffering to the 
same object.

ex obj1  a
   obj2  b
   obj1  c

a==c----> returns true.
a==b----> returns false.
 
Is This Answer Correct ?    6 Yes 2 No
Y.v.v.d.ravikanth
 
  Re: what is the difference between equals method and ==
Answer
# 5
equal method compare the the content of the strings,where 
as == compares the referance variables .
for example
string s1 = 'ramana'
string  s2= ' ramana'
if(s1==s2)
s.o.p("s1, s2 are same");
else
s.o.p(" s1, s2 are not same"); 

ans = s1,s2 are not same because == compares the referance 
variables.
 
Is This Answer Correct ?    2 Yes 1 No
Ramanareddy333
 
  Re: what is the difference between equals method and ==
Answer
# 6
Hi...
"equals()" method always compares the content of an 
object,but "==" operator compares the memory locations
(references).
eg: String s1="KOTAGUDIBANDA";
Where "s1" is a reference and "KOTAGUDIBANDA"is a content.
 
Is This Answer Correct ?    2 Yes 2 No
Devarathnam C,kotagudibanda(po
 
  Re: what is the difference between equals method and ==
Answer
# 7
Hi Ravi,
a==c----> returns true, only if obj1 c = a.
 
Is This Answer Correct ?    1 Yes 1 No
Leo Zhao
 
  Re: what is the difference between equals method and ==
Answer
# 8
== checks wheather two strings are pointing to same location
or not.

equals method checks wheather the strings are same or not
 
Is This Answer Correct ?    1 Yes 0 No
Upendar
 
  Re: what is the difference between equals method and ==
Answer
# 9
equals will compare two objects,== will compare whether two 
reference variables refer to same object or not
 
Is This Answer Correct ?    3 Yes 0 No
Ravikiran
 
  Re: what is the difference between equals method and ==
Answer
# 10
equals method will compare two strings where two strings are
equal or not but == method will compare reference variables.
 
Is This Answer Correct ?    1 Yes 1 No
Suganthi
 
  Re: what is the difference between equals method and ==
Answer
# 11
equal method also indirectly use == method i.e hashcode
(),there will be no difference b/w equals and == unless 
until u override the equal method

Let me know if iam wrong
 
Is This Answer Correct ?    1 Yes 0 No
Sriragv
 

 
 
 
Other Core Java Interview Questions
 
  Question Asked @ Answers
 
Can an anonymous class be declared as implementing an interface and extending a class?  1
Why Wait and notify are kept in Object class although they are used only with Thread Class Saksoft2
Read data from console and print in one file. That would be in C:\temp ? Thanks, Bose Oracle1
Differentiate constructor and a method and how are it be used? Wipro5
What is a super class and how super class be called?  3
Hi Friends, can u give me Real Time example for interface and abstract class.(With Banking Example)  1
What is singleton class?  6
What error occurs if a try-catch-finally statement sequence does not have a catch clause?  2
What is CardLayout? Infosys1
int a=1; float b=1.0; System.out.println(a==b); Honeywell8
When does the compiler supply a default constructor for a class? TCS8
what is polymorphism? Zensar5
What is non static block in java Ness-Technologies6
What is the use of anonymous inner classes ? HCL8
How Array List can be Serialized. Polaris5
What is "finally" keyword?  3
84. try { 85. ResourceConnection con = resourceFactory.getConnection(); 86. Results r = con.query(”GET INFO FROM CUSTOMER”); 87. info = r.getData(); 88. con.close(); 89. } catch (ResourceException re) { 90. errorLog.write(re.getMessage()); 91. } 92. return info; Which is true if a ResourceException is thrown on line 86? 1 Line 92 will not execute. 2 The connection will not be retrieved in line 85. 3 The resource connection will not be closed on line 88. 4 The enclosing method will throw an exception to its caller.  1
when asub class inherits a super class and overrides a public method of super class in sub class(public method in super class). why these methods needs to be public in sub class. (otherwise compile time error).  2
write a simple program inheritance? Polaris2
why we import both packages java.awt.*; and java.awt.event.*; as java.awt.*; can import all classes na. then what is the need of importing java.awt.event.*; ?  2
 
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