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. Hello, I'm using the above codes for my project. B
View Tutorial          By: Sandeep Dattaraju at 2011-02-26 11:01:48

2. Error loading SolarisSerial: java.lang.Unsatisfied
View Tutorial          By: amit doshi at 2009-04-06 02:00:28

3. its work well , thanks for code , but if any body
View Tutorial          By: mary at 2007-12-16 07:10:58

4. i want to Java coding's immediately
View Tutorial          By: vignesh at 2009-07-29 07:02:23

5. me too got the same problem....
but m sure

View Tutorial          By: HEHE at 2008-11-19 01:49:04

6. My question is, from where the name "java&quo
View Tutorial          By: Sreedevi at 2013-05-18 10:41:38

7. i am new in java so pls send insrutions in java
View Tutorial          By: shefeeja at 2012-10-09 02:22:15

8. Hi,
Downloaded all the five files but there

View Tutorial          By: Ratan at 2014-09-25 11:38:49

9. How to download any file when a button is in .jsp
View Tutorial          By: Gopesh at 2012-04-13 09:35:11

10. Good intro..
View Tutorial          By: thirunavukkarasu at 2015-01-30 17:32:10