Scenario in which implement or Write our own hascode and equals method

Dear All,
Please let me know in which circumstances we write our own Hashcode method and equals method not the default one provided by java.Kindly give me complete code and scenario.
Thanks
Sumit

Thanks for your reply
I have one more question.
When equal method of Object class give the same result as equals we override then why should we override equals.For example see the below code
public class EqualsTest{
public EqualsTest() {
     super();
public static void main(String[] args) {
Moof one =new Moof(8);
Moof two =new Moof(8);
if(one.equals(two))
System.out.println("one is equals to two");
class Moof {
private int moofvalue;
Moof(int val){
System.out.println("val inside moof constructor"+val);
moofvalue=val;
System.out.println("moofvalue inside moof constructor" +moofvalue);
public int getMoofValue()
System.out.println("moofvalue inside getmoffvalue method "+moofvalue);
return moofvalue;
public boolean equals(Object o)
System.out.println("Object o in equals"+o);
if( (o instanceof Moof) &&(( (Moof)o).getMoofValue()==this.moofvalue))
System.out.println("true");
return true;
else
System.out.println("false");
return false;
Here the output we get is :
val inside moof constructor8
moofvalue inside moof constructor8
val inside moof constructor8
moofvalue inside moof constructor8
Object o in equalsMoof@119c082
moofvalue inside getmoffvalue method 8
true
one is equals to two
The last output "one is equals to two" gives the same result as overridng equals by us.So why should we override equals here.
Thanks
Sumit

Similar Messages

  • My wife and I each have our own apple ID's which we use on our own iPhones and iPads. We share an iMac. Is there a way of enabling Facetime on the iMac to accept calls to either of our IDs without the need to login as that particular user?

    My wife and I each have our own apple ID's which we use on our own iPhones and iPads. We share an iMac. Is there a way of enabling Facetime on the iMac to accept calls to either of our IDs without the need to login as that particular user?

    no, when using facetime you log in with the apple id you want people to reach you at, so unless you both agree to share one apple id for all the facetime you do, it will be necessary for you to logout and login each time you use the application.

  • Help documents for APIs that are to be used to write our own apllication

    Hi,
    Iam using SUP 2.1 ESD#1 licensed version,
    There are no help documents for the APIu2019s that are to be used to write our own application, so can some one provide me with some docs.
    Thanks,
    B.Ushasri

    They are available online... what platform are you writing for? I'm assuming youre writing a Native app?
    Ian

  • HT2731 my wife and I share an itune account. we both have our own iphone and ipad. how do i share my contacts and calander information between my iphone and ipad but not own her devices

    my wife and I share an itune account. we both have our own iphone and ipad. how do i share my contacts and calander information between my iphone and ipad but not own her devices

    Have her get her own Apple ID and then set up Family Sharing: Start or join a family group using Family Sharing - Apple Support

  • My wife and I share apple id but have our own phones, and now having trouble with imessage

    My wife and I share apple id but have our own phones, and now having trouble with imessage. Sharing calenders, apps, music, contacts, etc...all great. But when we imessage each other. Our phones get confused and either not deliver message, or send it to and from itself.

    Go to Settings > Facetime and you will see "You can be reached for video calls at:"
    This should list your phone number (iPhone) and your email address (probably the gmail one).
    And then an option for "Add another email..."
    Choose that and enter your @me.com account and it'll send a verification email.
    Same for iMessage: Settings > Messages > "Receive at" > Add Another Email
    So you can be called by facetime and use iMessage through multiple email accounts yes.

  • How to remove the default theme from "Revolution theme" to create our own movies and put our own background..

    how to remove the default theme from 'Revolution theme" to create movies of our own and a background..
    how to create chapter maker for movies...

    Are you using iDVD? Or iMovie?
    If iDVD, post in -> https://discussions.apple.com/community/ilife/idvd.
    If iMovie, post in -> https://discussions.apple.com/community/ilife/imovie.
    Good luck,
    Clinton

  • My wife and i have iphone 4's and we want our own userids and passwords how do we change that?

    We have an ipad and two phones that all conect to each other and I want my own password and userid and she does too how do we fix that?

    For purchacing go to Settings>iTunes& App Stores, tap the Apple ID, sign out, sign back in with the other ID.  For iMessage go to Settings>Messages>Send & Receive and do the same thing.  For FaceTime go to Settings>FaceTime and do the same thing. 
    For iCloud, if your devices syncing data to the same iCloud account, on each device that will be changing iCloud accounts, go to Settings>iCloud and turn all data that is syncing with iCloud (contacts, calendars, etc.) to Off.  When prompted choose to keep the data on the device.  After everything is turned off, scroll to the bottom and tap Delete Account.  (This will only delete the account from this device, not from iCloud.  The device that will be keeping the account will not be effected by this.)  Next, set up a new iCloud account on the device using a different Apple ID and turn iCloud data syncing for contacts, etc. back to On.  When prompted, choose Merge.  This will upload the data to this new account.
    You will then have to go to icloud.com on your computer and sign into each iCloud account separately and manually delete the unwanted data (such as deleting the other person's contacts from your account, and vice versa).  These changes will be reflected on your devices.

  • HT204053 How do my husband and I make our own passwords and user names? We are Shari

    My husband and I have the same user names and password for our iPads 4and iPhones. When one of downloads onto a device, it goes to both devices. Also, he gets my reminders. I want to keep the user name and password and he will then get his ow ones. How do we go about doing this?
    When I looked into doing this on apple site, it seemed to show that I can change them, but not just change one of them

    He should go to http://appleid.apple.com and create a new ID - it's best to have a non-Apple address to do this with but it must be one that hasn't been previously associateds with an Apple ID. A free one from GMail or Yahoo would do.
    He should then sign out in System Preferences>iCloud, whereupon all the contact, calendar and Mail data from your iCloud account will disappear. He can then sign in with the new ID and create a separate account. He can share some of your data if he wants to by signing in with your account in System Preferences>Mail, Contacts and Calendars and checking just that sort of data there.
    None of this affect iTunes Store purchases. He will need to sign out in the iTunes Store (click the name at left of the black toolbar and choose 'Sign out' and then sign in with his new ID. However if he has made app purchases on your ID he will not be able to update them, or view films: you can't move purchases from one account to another and you can't keep changing the sign-in to the Store either. It's quite possible for him to retain your ID in iTunes but have his own in iCloud as the two are not connected.

  • My wife and I share Itunes acct we each have our own iphone and wish to have seperate acct.s how do we set it up

    We share Itunes acct. We wish to have single acct.s for each iphone plz help

    There is no way to split or merge Apple ID's.
    That being said, it is possible to have content from multiple ID's on a single device.
    Always use seperate ID's for iMessage unless you want to get each others iMessages.
    You can use the same Apple ID for iCloud which will allow for downloading automatically the content wirelessly on the device.  This may be annoying though if you turn on automatic syncing of apps.
    The best solution is to use a shared library in iTunes and sync the content you desire from the computer.  Then use a single but seperate Apple ID on each device.
    How to use multiple devices with a single computer

  • When do we override our own clone method not the Object class clone method

    Hi,
    I have a confusion in overriding clone method.We can create clone object by writing Object.clone() but some times I have seen writing our own clone method ,when do we write this,also clone() is defined protected and when we write our own clone it is said to write it public,why?
    Thanks
    Sumit

    protected methods can only be called in the same class and it subclass. You can make clone protected if this is all you need.
    However if you need to clone() the object from another class, it need to be public.
    This is the same for any method.
    Also as Object.clone() is protected you cannot make it private or package-local (this is true of any protected method)

  • Why we will prefer our own programs to load master data .

    Hi gurus ,
    What are the techniques involved in using SAP supplied programs
    why we will  prefer to write our own programs to load master data.
    Thanks and Regards :
    B.Madhu sudhan reddy
    Moderator message - Please ask a specific question - post locked
    Edited by: Rob Burbank on Dec 2, 2009 9:20 AM

    Hi Madhu,
        Sap has already have their own predefined upload programs in LSMW for Master Data .
    Techniques To Load Master Data in SAP :
    1) BAPI
    2) LSMW
    3) BDC (Call Transaction & Session Method)
    Regards,
    Sudhakar Reddy.A

  • Licensing issues for selling our own java app.

    hi guys,
    I am just wondering whether it is legal to write our own java applications and sell them to the public. Do I need to obtain a license from SUN or other third parties that provide me the support libraries(for example apache xalan, etc...)? You know, we are just normal individuals, there is no way we can afford the license.

    If you have to include code that you didn't write (library or otherwise), ...Last time I checked the JRE could be distributed by a user. The JDK could not. If one uses only the the documented classes in the JDK/JRE then only the JRE is needed. If one is using any other products/api/undoc'd like javamail, j2ee, jmdk, etc then the license will have to be looked at.
    Stuff from free ware sources generally have varying restrictions. This can often include the demand that the product must be made available in source code form. There can be other variations, so the license for each download should be checked.

  • My husband and I each have our own iTunes library on our separate computers. Is there a way for us to share each other's music/playlists?

    My husband and I recently got married and we both have our own laptops and iPods with our own individual iTunes library. We would like to share the music we have downloaded over the years. I have read several discussions on the forums and think maybe Home Sharing is the way to go- but if I sign in my iTunes on my husband's computer, will it delete his iTunes library? I'm not very computer savvy.
    I tried attaching some songs as e-mails and sending them to him, but it would only allow him to add the songs I retrieved off of actual music CDs to his iTunes library- he could not add songs I had paid for through the store.
    If anyone could help us figure out if there is a way to share our music across both libraries/iPods, we would be greatly appreciative!!
    -K
    Also, we use Windows, not Macs, if that makes a difference. Thanks in advance!!!

    if I sign in my iTunes on my husband's computer, will it delete his iTunes library?
    LOL!  If Home Sharing deleted the other person's library, then Home Sharing wouldn't have too many users, would it?
    Seriously, Home Sharing sounds like a fine solution to the need you express. 
    However, your question suggests that your library is not backed up, right?  You and your husband should each make a backup of your libraries.

  • Implementing evetns in my own classes

    I am currently developing a class that I want to enable with events so that consumers of my class can get feedback of class activity.
    So consumers should be able to add listeners (containing callback methods) to instances of the class. Although my current class is GUI related (I am writing my own tablemodel) my issue is not limited to GUI development I think (therefore posted here and not in Swing forum).
    So far I am a little familiar with Listener and Adapter classes but now the point:
    Do I have to implement my own addBlaBlaListener and removeBlaBlaListener methods implementing my own methods to handle the list of current listeners (e.g. choosing the appropriate array, list, stack or whatever classes to store the references) or is there some ready-made-classes from the libraries that should/can be used?

    tjacobs01 wrote:
    Why do you need to create UI-style events?I am building my own Table model as the simple table model is too basic for my common needs. In that table model I need to provide events being fired when table cells change.
    I highly recommend using the Observable/Observer pattern where possible. Otherwise, see an example for custom events in my InfoFetcher.FetcherListener interface
    http://forums.sun.com/thread.jspa?threadID=759854&tstart=62264
    I heard/read about the Observer and Observerable but when I searched for event handling I always found the methods I am currently trying. That's the only reason why I use that here - because this is what I found how others recommend to do it. If there is a better option - I am open and flexible - yet (in a year when everything was implemented probably not ;-) ).

  • I share my iTunes with my family's iPods.  We all buy music on our iPod's and would like to transfer the purchases to the iTunes library.  How would we do this?

    I share my iTunes with my family's iPod's.  We all buy music seperately on our own iPod and would like to transfer the music to our iTunes library, how would we do this?

    Oh jeez, that was simple. Thanks!

Maybe you are looking for

  • SOAP: call failed: java.lang.NullPointerException

    Hi, We are geeting the error in RWB --> SOAP: call failed: java.lang.NullPointerException We checked the communication channel and interface and all are working fine. Can anybody suggest? Regards, Akki..................

  • Upload/Refresh speed on Firefox 3.6.27 is sluggish on websites

    On crowdSPRING, a design creation community, my upload speeds are significantly slower and sometimes get stuck. Refresh doesn't consistently solve this. I'm running Firefox 3.6.27.

  • Passing Range to Function

    Hi all I would thank and reward with points to a correct answer. I have one range with many lines. Example of one line:   mob-sign = 'I'.   mob-option = 'EQ'.   mob-low = '50010031'.   append mob. Then I have to pass this range to a Function module t

  • Business Catalyst not fulling uploading site when trying to publish ???

    Can anyone help me please. I am trying to update some changes to a site I am creating but for some reason it keeps stopping upload at 76% upload when trying to publish. I have shut the program down, restarted my mac, logged in and out and in again to

  • Plugin firefox acrobat reader mac yosemite

    firefox non mi apre i documenti pdf da compilare. mi dice sempre che devo aggiornare alla versione più recente di acrobat reader, ma la mia è già la versione più recente il modulo da compilare in prova è sul sito del MUDE