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
Prepare Android Antivirus with locate device capability Project Description: We need a developer that can develop an Android Antivirus similar to lookout Developer need to prov

Explain abstract method in java? Java permits methods and classes to be declared abstract. An abstract method is not actually implemented in the class. It is merely declared th

Mike sells on the average 15 newspapers per week (Monday – Friday). Find the probability that 2.1 In a given week he will sell all the newspapers [7] 2.2 In a given day he will se

Explain the both HashSet and TreeSet? HashSet is an unordered, unsorted Set. It's a Collection set which restrict duplicate elements and also repositioning of elements. I

pebble merchant

Task 1 Create a new project in Eclipse called Assignment 1. Within this project create a package called task01. 1/ Download the class Date (you must use this class - no

how to write aprogramm that calculates gross pay, taxes, and net pay for both hourly and commission employees. It will then display those results to the screen

The problem statement is pretty simple. We need a software implementation of a Point of Sale terminal at a typical store. The users of the system are the cashiers sitting at the sa

How we Declaring Arrays in java language? Like all other variables in Java, an array must have a exact type such as byte, int, String or double. Just variables of the appropria