Page 3 of 3 FirstFirst 123
Results 31 to 40 of 40
  1. #31
    Senior Member
    Join Date
    Sep 2018
    Location
    Delhi
    Posts
    110
    Quote Originally Posted by priya01 View Post
    What is hashCode?
    A hashcode is a number generated from any object. This is what allows objects to be stored/retrieved quickly in a Hashtable.

  2. #32
    Registered User
    Join Date
    Aug 2018
    Location
    Sydney
    Posts
    17
    A hashcode is a number generated from any object. This is what allows objects to be stored/retrieved quickly in a Hashtable.
    Imagine the following simple example:
    On the table in front of you you have nine boxes, each marked with a number 1 to 9. You also have a pile of wildly different objects to store in these boxes, but once they are in there you need to be able to find them as quickly as possible.
    What you need is a way of instantly deciding which box you have put each object in. It works like an index; you decide to find the cabbage so you look up which box the cabbage is in, then go straight to that box to get it.
    Now imagine that you don't want to bother with the index, you want to be able to find out immediately from the object which box it lives in.
    In the example, let's use a really simple way of doing this - the number of letters in the name of the object. So the cabbage goes in box 7, the pea goes in box 3, the rocket in box 6, the banjo in box 5 and so on. What about the rhinoceros, though? It has 10 characters, so we'll change our algorithm a little and "wrap round" so that 10-letter objects go in box 1, 11 letters in box 2 and so on. That should cover any object.
    Sometimes a box will have more than one object in it, but if you are looking for a rocket, it's still much quicker to compare a peanut and a rocket, than to check a whole pile of cabbages, peas , banjos and rhinoceroses.
    That's a hash code. A way of getting a number from an object so it can be stored in a Hashtable. In Java a hash code can be any integer, and each object type is responsible for generating its own. Lookup the "hashCode" method of Object.

    The hashcode of a Java Object is simply a number, it is 32-bit signed int, that allows an object to be managed by a hash-based data structure. We know that hash code is an unique id number allocated to an object by JVM. But actually speaking, Hash code is not an unique number for an object. If two objects are equals then these two objects should return same hash code. So we have to implement hashcode() method of a class in such way that if two objects are equals, ie compared by equals() method of that class, then those two objects must return same hash code.

  3. #33
    Registered User
    Join Date
    Mar 2019
    Location
    Ahmedabad
    Posts
    180
    The hashcode of a Java Object is simply a number, it is 32-bit signed int, that allows an object to be managed by a hash-based data structure. We know that hash code is an unique id number allocated to an object by JVM. But actually speaking, Hash code is not an unique number for an object. If two objects are equals then these two objects should return same hash code. So we have to implement hashcode() method of a class in such way that if two objects are equals, ie compared by equal() method of that class, then those two objects must return same hash code. If you are overriding hashCode you need to override equals method also.

  4. #34
    Senior Member
    Join Date
    Nov 2018
    Posts
    1,853
    The purpose of the hashCode() method is to provide a numeric representation of an object's contents so as to provide an alternate mechanism to loosely identify it. By default the hashCode() returns an integer that represents the internal memory address of the object.

  5. #35
    Senior Member
    Join Date
    Aug 2020
    Posts
    1,517
    A hashcode is an identity of an object. It is used to differentiate one object from another object. Every object in java has its own unique hashcode.

  6. #36
    Registered User
    Join Date
    Nov 2013
    Posts
    905
    The hashcode of a Java Object is simply a number, it is 32-bit signed int, that allows an object to be managed by a hash-based data structure. We know that hash code is an unique id number allocated to an object by JVM. But actually speaking, Hash code is not an unique number for an object. If two objects are equals then these two objects should return same hash code. So we have to implement hashcode() method of a class in such way that if two objects are equals, ie compared by equal() method of that class, then those two objects must return same hash code. If you are overriding hashCode you need to override equals method also.

  7. #37
    Senior Member
    Join Date
    Nov 2018
    Posts
    1,853
    A hash code is an integer value that is associated with each object in Java. Its main purpose is to facilitate hashing in hash tables, which are used by data structures like HashMap.

  8. #38
    A hash code is an integer value associated with each object in Java. Its main purpose is to promote hashing in hash tables, which are used by data structures like HashMap.

  9. #39
    Junior Member
    Join Date
    Mar 2017
    Location
    8341, woodword st. Savage, MD 20763
    Posts
    6
    A hash code is an integer value that is associated with each object in object oriented programming language. Its main purpose is to facilitate hashing in hash tables, which are used by data structures like HashMap.

    https://www.yatharthmarketing.com/sales-consultant.html | https://www.yatharthmarketing.com/co...-programs.html | https://www.yatharthmarketing.com/sales-training-programs.html | https://www.yatharthmarketing.com/le...-programs.html

  10. #40
    Senior Member
    Join Date
    Nov 2018
    Posts
    1,853
    The hashCode method is an inbuilt method that returns the integer hashed value of the input value. ... If two or more objects are equal according to the equals method, then their hashes should be equal too. If two or more objects are not equal according to the equals method, then their hashes can be equal or unequal.

Page 3 of 3 FirstFirst 123

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

  Find Web Hosting      
  Shared Web Hosting UNIX & Linux Web Hosting Windows Web Hosting Adult Web Hosting
  ASP ASP.NET Web Hosting Reseller Web Hosting VPS Web Hosting Managed Web Hosting
  Cloud Web Hosting Dedicated Server E-commerce Web Hosting Cheap Web Hosting


Premium Partners:


Visit forums.thewebhostbiz.com: to discuss the web hosting business, buy and sell websites and domain names, and discuss current web hosting tools and software.