Basic difference between equals and identity method, JAVA Programming

 

The == gives true, if the variable reference points to the similar types of object in memory. That is a "shallow comparison".

 

The equals () - gives the results of running the equals() method of a user supplied class, which differentiate the attribute values. The equals() method gives "deep comparison" by comparing if two objects are logically same as opposed to the shallow comparison given by the operator ==.

If equals () function does not exist in a user supplied class then the inherited Object class's equals () method is run which evaluates if the references point to the similar object in memory. The object.equals() performs just same as the "==" operator.

Overriding the Object class may seem easy but there are many ways to get it worse, and consequence may be unpredictable behavior.

 

1309_Untitled.png

Posted Date: 7/25/2012 1:34:34 AM | Location : United States







Related Discussions:- Basic difference between equals and identity method, Assignment Help, Ask Question on Basic difference between equals and identity method, Get Answer, Expert's Help, Basic difference between equals and identity method Discussions

Write discussion on Basic difference between equals and identity method
Your posts are moderated
Related Questions
Write a program to add integer value? class AddInts { public static void main (String args[]) { int i = 1; int j = 2; System.out.println("i is " + i); System.out.println("

String concatenation and comparison public class StringTest { public static void main(String[] args) { int i = 4; int j = 5; System.out.println ("Hello" + i); // wi

What is an object's lock and which objects have locks? An object's lock is a mechanism that is used by multiple threads to get synchronized access to the object. A thread may i

What is the use of UnicastRemoteObject in RMI? Ans) The UnicastRemoteObject class gives support for point-to-point active object references using TCP streams. Objects that need

what are cookies?

Question : (a) Class file verification in CLDC is different from class file verification in J2SE. Explain and discuss how and why it is different, illustrating your answer

In Java everything exists within a class. It describes the behavior of the class and its characteristics. Java applications and applets are built in the class. Rules present for cl

I want to know if you can help me with a javacard programming project

Machines should have Java interpreter for the Java byte code to get implemented. Linking is a very simple process and this feature helps while developing applications. Java compile

The fancy new French restaurant La Food is very popular for its authentic cuisine and high prices. This restaurant does not take reservations. To help improve the efficiency of the