Java Fundamentals Hardening 49:java in hash code

Source: Internet
Author: User

1. Concept:

The hash is actually just a concept, and there is no real point. Its purpose is to ensure that the data is evenly distributed within a certain range. So it is perfectly possible to generate the same hash code for different data.

Now is the Java Virtual machine in the perspective of the layout of the memory, stand in the Java Virtual machine angle, in memory there are many many objects, here with an ellipse to represent the object. When a program runs, there may be many objects in memory allocated, then for the Java Virtual machine, it needs to find the address of these objects, how to find the address of these objects? Java Virtual opportunity uses a table to record where each object is located, and this table is generally encoded with a hash code, each object has its own unique hash code, according to this code can find the relevant object, that is, according to this code you can uniquely determine the object, And can quickly determine the location of this object, you can simply understand the role of hash coding. But Java itself is a bit of a problem with the implementation of hash coding, it can be two objects, the content is different, but their hash code can actually be the same, and this probability is very high.

2. The implementation of the hash code is a bit problematic, it may be two objects, the content is different, but their hash code can actually be the same, and this probability is very high?

A: Of course, it is possible, in fact, as long as you understand. Hashcode is a 32-bit integer, so long as there are more than 2^32 objects in memory, there must be at least two hashcode of the same object.

Java Fundamentals Hardening 49:java in hash code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.