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.



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
Explain java.util.Random package? The java.util.Random class permits you to create objects which generates pseudo-random numbers along with uniform or gaussian distributions ac

Relate Java with C/C++ Very similar C/C++ syntax, operators, etc. Core language is simpler than C++ -- no pointers, no operator overloading, and no multiple inheritance.

An aspect is the cross-cutting functionality that you are executing. It is the aspect of your application you are modularizing. An example of an aspect is logging. Logging is somet

How can you define a consistent web design? Why is it needed? A consistent excellent designed website is generated for common public which permits users to attain what they nee

On the surface, an application context is similar as a bean factory. But application context offers much more.. ? Application contexts give a means for resolving text messages,

Are you real? I dont want to get help from a computer

how to quit from unlimitedly executing applet

implement simulated annealing for cable company problem

A for loop repeats until a specified condition evaluates to false. For for loop the JavaScript is similar to the Java and C for loops. A for statement looks as:  for ([initial-