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 want to need SCJD Dums. so please help me that w
View Tutorial          By: Dayamay singh at 2009-01-03 00:07:06

2. Hi

Anybody plz send me the sms send

View Tutorial          By: Venky at 2008-11-19 08:33:22

3. Shouldn't you call free() on the allocated memory
View Tutorial          By: Ritchie at 2012-05-09 14:14:49

4. Thanks a lot for that excellent explanation. It ha
View Tutorial          By: Gregory at 2014-12-30 05:49:21

5. Hello,
could you send me the complete code

View Tutorial          By: Sanjay at 2013-04-19 07:28:12

6. how to trim in jsp page and to send the trimed con
View Tutorial          By: monishaa at 2015-07-16 10:06:11

7. this is i got error msg when i run a my program .
View Tutorial          By: anbu at 2009-04-08 02:41:17

8. gud tutorial but the permission denied is because
View Tutorial          By: amithooda at 2012-06-11 06:43:00

9. hi thanks for your tutorial, but I can`t run your
View Tutorial          By: yashar at 2015-05-29 18:57:30

10. thanks
View Tutorial          By: sowmya at 2012-07-10 14:22:50