Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

Hi, well i am unable to understand that why it is mandatory
to have same hashcode, if two objects are same?

Thanks in advance.

Answer Posted / rajshekaran pillai

As the JVM assigns the hashcode to an object value and not
the reference the hashcode for the same object will be same.
the equals() method of the object class uses this hashcode
to evaluate if the objects have same value. therefore

Object o1 = new String("ABC");
Object o2 = "ABC";

/**
* will have the same hashcode
* therefore when we do..
*/
if(o1 == o2){
System.out.println("The object reference is same");
}else if(o1.equals(o2)){
System.out.println("The object has same value");
}

/**
* The output is
* The object has same value
*/

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain wait(), notify() and notifyall() methods of object class ?

1043


What are different types of expressions?

1120


Is oracle charging for java?

1034


What is use of map in java?

1011


What is the difference amongst jvm spec, jvm implementation, jvm runtime ?

968


What is a cup of java?

1018


Objects or references which of them gets garbage collected?

968


Explain the difference between protected and default access.

998


Give us the name of the list layoutmanagers in java?

927


What are untrusted applets?

1144


What is string intern in java?

1023


What are assembly attributes?

1008


Explain the difference between map and flatmap stream operation?

1268


What is the purpose of using bufferedinputstream and bufferedoutputstream classes?

1071


What are the approaches that you will follow for making a program very efficient?

1077