Comment on Tutorial - equals( ) Versus == in Java By Mashoud



Comment Added by : Javin @ eclipse remote debugging

Comment Added at : 2011-04-09 06:50:44

Comment on Tutorial : equals( ) Versus == in Java By Mashoud
Here is my approach for writing equals() method from <a href="http://javarevisited.blogspot.com/2011/02/how-to-write-equals-method-in-java.html">How to write equals method in Java</a>

1) Do this check -- if yes then return true.
2) Do null check -- if yes then return false.
3) Do the instanceof check if instanceof return false than return false
4) Type cast the object; note the sequence instanceof check must be prior to casting object.
5) Compare individual attribute start with numeric attribute because comparing numeric attribute is fast and using short circuit operator so if first field does not match , don't try to match rest of attribute and return false.


View Tutorial



Subscribe to Tutorials

Related Tutorials

Program using concept of byte long short and int in java

Update contents of a file within a jar file

Tomcat and httpd configured in port 8080 and 80

Java File

Java String

Count number of vowels, consonants and digits in a String in Java

Reverse a number in Java

Student marks calculation program in Java

Handling Fractions in Java

Calculate gross salary in Java

Calculate average sale of the week in Java

Vector in Java - Sample Program

MultiLevel Inheritance sample in Java

Multiple Inheritance sample in Java

Java program using Method Overriding

Archived Comments

1. I need dumps for practice
View Tutorial          By: Sanket barge at 2011-06-17 10:05:16

2. Thank you. I found this very helpful.
View Tutorial          By: tavella at 2014-09-26 01:04:13

3. hi i am new to JSP wht is class.forname in the cod
View Tutorial          By: chanti at 2011-05-07 03:02:26

4. what about asp.net?
View Tutorial          By: tradeready at 2009-05-06 03:04:20

5. HI,
I am getting this error
Error lo

View Tutorial          By: vijay bhanu at 2009-07-18 08:57:57

6. thank you so much i learn from your tutorial i wis
View Tutorial          By: Anonymous at 2009-01-03 20:08:41

7. I do not understand this line:
Map.Entry me

View Tutorial          By: hap Og at 2011-11-03 01:42:33

8. easy to understand and it helped me a lot in prepa
View Tutorial          By: shandini at 2011-04-14 13:14:33

9. Hii.... We are B.Tech 4th year students. We are wo
View Tutorial          By: Shipra Malik at 2010-08-17 03:32:34

10. Very Nice and Concrete Explanation ..
View Tutorial          By: Parvesh at 2009-09-18 11:11:00