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
JNLP/ Java Application - GUI and Backend Projects Project Description: I am looking for assist in making changes to a complex java application. System launches from web pa

In this programming assignment, you are going to implement the simple distributed ticket reservation system (DTRS) from Assignment 1 in CORBA using Java IDL. In addition to the thr

To simplify complex class diagrams you may group classes into packages.

Need the following code in double var instead of integer. import javax.swing.*; public class arrayVar { public static void main (String[] args) //This is our main method prompt

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,

Objective: create a simple object, put that object in a simple collection class, use that object and collection in a simple GUI application. Specification:  Consider a Librar

What does TCP/IP stand for? TCP/IP is a Protocol type basically it is known by Transmission Control Protocol/Internet Protocol

What are the types of Dependency Injection Spring supports? Ans) there are two types of Dependency Injection Spring a)  Setter Injection: b)  Constructor Injection:

Your task for this assignment is to define multiple classes via inheritance. Your classes should implement various "snacks" including "M&Ms", "Popcorn", etc. To begin, create an a

A joinpoint is a point in the implementation of the application where an aspect can be plugged in. This point could be a method being called, an exception being thrown, or even a f