Tag

HashCode

0 views collected around this technical thread.

macrozheng
macrozheng
Nov 27, 2024 · Backend Development

How a Tiny HashMap Bug Triggered a Massive Memory Leak in a High‑Traffic Microservice

A senior architect introduced a high‑concurrency monitoring feature that used a ConcurrentHashMap without proper equals/hashCode implementations, leading to duplicate keys, race conditions, and severe memory leaks, which were later resolved by correcting the key class and applying atomic map operations.

ConcurrentHashMapHashCodeMemoryLeak
0 likes · 8 min read
How a Tiny HashMap Bug Triggered a Massive Memory Leak in a High‑Traffic Microservice
Top Architect
Top Architect
Jan 23, 2022 · Fundamentals

Understanding Java Float hashCode: Why -0.0 and 0.0 Behave Differently as Map Keys

This article explains how Java's Float hashCode treats 0.0 and -0.0 as distinct values, causing unexpected behavior when using floating‑point numbers as HashMap keys, and shows how to debug, reproduce, and avoid the issue by using alternative representations.

HashCodeHashMapfloat
0 likes · 10 min read
Understanding Java Float hashCode: Why -0.0 and 0.0 Behave Differently as Map Keys
Selected Java Interview Questions
Selected Java Interview Questions
Sep 29, 2021 · Fundamentals

Why and How to Override hashCode() and equals() in Java

This article explains why Java developers must override both hashCode() and equals() methods for proper object comparison in hash-based collections, outlines the scenarios requiring such overrides, and provides detailed example code demonstrating correct implementations.

CollectionsHashCodeHashSet
0 likes · 7 min read
Why and How to Override hashCode() and equals() in Java
Full-Stack Internet Architecture
Full-Stack Internet Architecture
Jul 20, 2021 · Fundamentals

Understanding Java Math.abs and Handling Integer.MIN_VALUE Edge Cases

This article explains the concept of absolute value, demonstrates Java's Math.abs overloads for different primitive types, illustrates a common hashing use‑case that can fail when Integer.MIN_VALUE is processed, and shows how casting to long resolves the overflow problem.

HashCodeLongabsolute-value
0 likes · 5 min read
Understanding Java Math.abs and Handling Integer.MIN_VALUE Edge Cases
Selected Java Interview Questions
Selected Java Interview Questions
Nov 6, 2020 · Fundamentals

Understanding Java hashCode() and equals(): Design Principles and Practical Examples

This article explains the rules and design principles behind Java's hashCode() and equals() methods, illustrates their implementations in String, and provides concrete Person class examples showing how proper overriding affects Set and Map behavior.

HashCodedesign principlesequals
0 likes · 10 min read
Understanding Java hashCode() and equals(): Design Principles and Practical Examples
IT Xianyu
IT Xianyu
Oct 12, 2020 · Fundamentals

Understanding equals() and hashCode() in Java: When They Matter

This article explains the roles of equals() and hashCode() in Java, demonstrates how their interaction affects hash‑based collections like HashSet, provides multiple code examples showing correct and incorrect implementations, and outlines essential principles for overriding these methods to ensure proper object equality handling.

CollectionsHashCodeHashSet
0 likes · 9 min read
Understanding equals() and hashCode() in Java: When They Matter
Architecture Digest
Architecture Digest
Sep 4, 2020 · Backend Development

Understanding HashMap: Why Overriding hashCode and equals Is Essential

This article explains how HashMap stores data using hash functions, illustrates hash collisions and chain addressing, and demonstrates why overriding hashCode and equals in custom key classes is essential for correct retrieval, using Java code examples and interview insights.

Data StructuresHashCodeHashMap
0 likes · 9 min read
Understanding HashMap: Why Overriding hashCode and equals Is Essential
macrozheng
macrozheng
Aug 6, 2020 · Backend Development

When ‘No‑Comment’ Java Code Triggers a Memory Leak – A ConcurrentHashMap Study

A newly hired architect boasts high‑concurrency expertise but writes un‑commented Java code that misuses ConcurrentHashMap, leading to memory leaks; the ensuing investigation reveals missing equals/hashCode implementations, race conditions in a visit method, and a debate between synchronized blocks and putIfAbsent for safe updates.

Backend DevelopmentConcurrentHashMapHashCode
0 likes · 8 min read
When ‘No‑Comment’ Java Code Triggers a Memory Leak – A ConcurrentHashMap Study
Java Captain
Java Captain
Jul 11, 2020 · Backend Development

Why Overriding hashCode and equals Is Essential for Custom Keys in Java HashMap

This article explains how HashMap stores data using hash functions, illustrates the impact of hash collisions, and demonstrates with Java code why custom objects used as keys must override both hashCode and equals to work correctly in interviews and real projects.

HashCodeHashMapInterview
0 likes · 9 min read
Why Overriding hashCode and equals Is Essential for Custom Keys in Java HashMap
Sohu Tech Products
Sohu Tech Products
May 13, 2020 · Fundamentals

Deep Dive into Java HashMap: Implementation, hashCode/equals, Collision Handling, and Interview Questions

This article provides a comprehensive overview of Java's HashMap, covering its place in the Set and Map families, internal implementation details, the relationship between hashCode() and equals(), collision resolution strategies, basic operations, differences from Hashtable, and several classic interview problems such as Top‑K frequency and LRU cache design.

Data StructuresHashCodeHashMap
0 likes · 14 min read
Deep Dive into Java HashMap: Implementation, hashCode/equals, Collision Handling, and Interview Questions
Selected Java Interview Questions
Selected Java Interview Questions
Dec 4, 2019 · Fundamentals

Understanding Java HashMap: Implementation Principles, JDK7 Source Walkthrough, and Interview Insights

This article explains the fundamentals of hash tables, dives deep into Java's HashMap implementation—including JDK7 source code analysis of its internal structures, resizing logic, and key methods—while also covering common interview questions such as why the array size must be a power of two and the necessity of overriding both equals and hashCode.

Data StructuresHashCodeHashMap
0 likes · 19 min read
Understanding Java HashMap: Implementation Principles, JDK7 Source Walkthrough, and Interview Insights
Architect's Tech Stack
Architect's Tech Stack
Dec 1, 2019 · Fundamentals

Why Java's String.hashCode Uses 31 as Multiplier: Theory and Experiments

This article explores the rationale behind Java's String.hashCode method using the multiplier 31, detailing its implementation, mathematical justification, performance optimizations, and experimental analysis of hash collision rates with various multipliers, concluding why 31 is an optimal choice.

HashCodePerformancecollision analysis
0 likes · 15 min read
Why Java's String.hashCode Uses 31 as Multiplier: Theory and Experiments
Selected Java Interview Questions
Selected Java Interview Questions
Oct 27, 2019 · Fundamentals

Understanding the Relationship Between hashCode() and equals() in Java

This article explains how Java's hashCode() and equals() methods interact, illustrates their behavior with and without hash‑based collections through multiple code examples, and outlines the essential principles developers must follow when overriding these methods to ensure correct functionality in hash tables.

HashCodeHashMapHashSet
0 likes · 11 min read
Understanding the Relationship Between hashCode() and equals() in Java
Java Captain
Java Captain
Sep 30, 2019 · Fundamentals

Why Java's String.hashCode() Uses 31 as Multiplier: Theory, Experiments, and Visualization

This article explains why Java's String.hashCode() uses the multiplier 31, covering its implementation, mathematical justification, JVM optimization, comparative analysis with other multipliers, and experimental results on hash collision rates and distribution using a large English word dataset.

HashCodePerformancealgorithm
0 likes · 15 min read
Why Java's String.hashCode() Uses 31 as Multiplier: Theory, Experiments, and Visualization
Java Captain
Java Captain
Mar 12, 2019 · Fundamentals

Java Basics Interview Questions and Answers – Part 1

This article presents a curated set of 208 Java interview questions, focusing on the Java Basics module, and provides detailed explanations, code examples, and analyses of concepts such as JDK vs JRE, == vs equals, hashCode, final, abstract classes, and common String operations.

HashCodeInterviewJDK
0 likes · 14 min read
Java Basics Interview Questions and Answers – Part 1
Java Architect Essentials
Java Architect Essentials
Jul 11, 2018 · Backend Development

Understanding Java HashMap hashCode and Hash Algorithm

This article explains the fundamentals of binary operations, why hashCode is used, how Java's String hashCode is implemented, the rationale behind using the multiplier 31, and the detailed workings of HashMap's hash function, index calculation, capacity choices, and custom sizing recommendations.

Data StructuresHashCodeHashMap
0 likes · 13 min read
Understanding Java HashMap hashCode and Hash Algorithm
Java Captain
Java Captain
Dec 28, 2017 · Fundamentals

Java Programming Essentials: Implementing equals, hashCode, compareTo, clone, and Common Idioms

This article presents a collection of essential Java programming practices, covering how to correctly implement equals, hashCode, compareTo, clone, use StringBuilder, generate random numbers, manage threads, handle I/O with try‑finally, perform defensive checks, and manipulate arrays and primitive packing.

Best PracticesCollectionsHashCode
0 likes · 14 min read
Java Programming Essentials: Implementing equals, hashCode, compareTo, clone, and Common Idioms