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. thats good
View Tutorial          By: P.Kumar at 2009-08-02 10:48:48

2. good tutorial for beginners..........
View Tutorial          By: Madarapu naveen at 2011-06-18 11:19:50

3. How can i download the comm.API .
pls tel

View Tutorial          By: Sajeer kc at 2015-01-16 04:12:28

4. when i copy paste your program or source code

View Tutorial          By: hello at 2010-07-09 18:56:23

5. Nice example..i m working on android and i want to
View Tutorial          By: Pranav at 2012-04-25 07:00:48

6. You are a life saver. My Production website was do
View Tutorial          By: Caricus at 2011-04-07 23:58:37

7. @Vipin : vipin u r wrong,,,in reality java does n
View Tutorial          By: Arpit Tyagi at 2010-07-23 04:11:20

8. Hi, i am newly in java,please send me on sample pr
View Tutorial          By: aruna.k at 2012-12-13 06:05:44

9. Fantastic work guys
View Tutorial          By: wizard at 2012-09-22 04:18:59

10. This is good for beginners.
View Tutorial          By: sathish at 2011-04-05 11:37:30