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. while i am executing this program i am getting Nul
View Tutorial          By: Seema at 2013-11-26 18:39:15

2. hi i need moving clock javascript code...please se
View Tutorial          By: madhavan at 2008-10-19 21:59:45

3. Is there a code that can hide smses, when they ent
View Tutorial          By: James at 2010-11-18 03:32:56

4. Nice for java examples, it is easy to understand j
View Tutorial          By: Nirmaladevi.T at 2009-06-19 04:42:51

5. hi, i would like to know about sms sendimg via web
View Tutorial          By: abhi at 2008-07-09 07:28:54

6. i am a bca student. i want to know more about garb
View Tutorial          By: ahana at 2011-06-26 11:02:36

7. Would u please provide me with a solution about ho
View Tutorial          By: milan at 2011-02-17 05:39:38

8. I'm working on an intranet site/web application. W
View Tutorial          By: Tony Gingrich at 2011-10-23 21:22:31

9. Nice site to assist learners to study without much
View Tutorial          By: Hot.g at 2009-12-01 02:36:02

10. i want to study java
View Tutorial          By: doshyo at 2007-12-13 07:41:03