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. Hi, thanks for your code, I have modified a little
View Tutorial          By: Armando at 2010-08-10 09:34:35

2. plz can u give me code for key excange b/n pda &am
View Tutorial          By: visnas at 2009-05-04 20:18:32

3. This is very much useful to me to complete my assi
View Tutorial          By: Eva Jhonson at 2012-09-30 16:44:08

4. Your explanation is good and okay but, it will be
View Tutorial          By: Emmanuel at 2009-05-28 02:45:11

5. hello, this code was compiled correctly, bt it wil
View Tutorial          By: anand vijay singh at 2014-05-03 12:47:24

6. i like this a lot
View Tutorial          By: raj at 2011-05-06 06:15:36

7. Thanks this tutorial helped me :)
View Tutorial          By: Anuja at 2012-07-17 06:59:39

8. NICE SITE
View Tutorial          By: MAEN ZIAD HUDAIB at 2009-07-01 01:55:28

9. This example is working fine....I think BillGates
View Tutorial          By: Monoj Rath at 2010-07-15 01:27:51

10. This code rocks!! any one having any trouble shoul
View Tutorial          By: Ankur at 2010-01-22 06:37:10