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 you will run this program just as you run any o
View Tutorial          By: Steven at 2008-10-14 09:03:28

2. Hi,
Pls help me.I need a full java code wit

View Tutorial          By: karan at 2009-11-26 11:29:56

3. Nice Article.
View Tutorial          By: Swathi Kumar at 2012-04-15 10:44:14

4. Wow, damn nice. It does everything, and the script
View Tutorial          By: Ethan Windsor at 2012-06-14 13:47:39

5. could you please send me a complete appointment re
View Tutorial          By: Jaylon aron at 2010-02-21 02:22:57

6. I faced an exception "java.net.connectExcepti
View Tutorial          By: Sandhya Rani Vellanki at 2010-11-15 00:39:24

7. its good
View Tutorial          By: sumanth at 2010-04-10 20:10:00

8. hello guys... plz help me in j2me i want to learn
View Tutorial          By: bishnu prakash at 2011-07-11 13:18:39

9. the article is very useful...!
View Tutorial          By: pravin salame at 2011-05-20 11:58:28

10. hi can u send me the complete working code for sen
View Tutorial          By: Amit Adhikaree at 2011-03-22 17:47:49