Tagged articles
32 articles
Page 1 of 1
ITPUB
ITPUB
Dec 22, 2024 · Fundamentals

Why Does Comparing Two Integer Objects in Java Sometimes Return True?

This article explains why using the == operator on two Integer objects in Java can yield true for some values and false for others, covering Integer caching, the role of Integer.valueOf, and the correct way to compare Integer values with equals.

JavaObject Comparisonequals
0 likes · 7 min read
Why Does Comparing Two Integer Objects in Java Sometimes Return True?
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.

ConcurrentHashMapJavaMemoryLeak
0 likes · 8 min read
How a Tiny HashMap Bug Triggered a Massive Memory Leak in a High‑Traffic Microservice
Rare Earth Juejin Tech Community
Rare Earth Juejin Tech Community
Dec 28, 2023 · Fundamentals

Understanding Comparison Methods in Java

This article explains various comparison methods in Java, including equality operators, the equals() method, Comparator and Comparable interfaces, and provides code examples for primitive, object, string comparisons, as well as custom sorting logic, highlighting their roles in sorting, searching, and data handling.

ComparableComparatorComparison
0 likes · 14 min read
Understanding Comparison Methods in Java
Java Backend Technology
Java Backend Technology
Sep 25, 2022 · Fundamentals

6 Common Java Pitfalls Every Developer Should Avoid

This article highlights six frequent Java pitfalls—including misuse of == with Integer, Objects.equals quirks, BigDecimal precision loss, Stream filter side‑effects, auto‑unboxing null errors, and String replace nuances—providing code examples and best‑practice recommendations to help developers write safer, more reliable code.

Auto-unboxingBigDecimalJava
0 likes · 12 min read
6 Common Java Pitfalls Every Developer Should Avoid
Programmer DD
Programmer DD
Aug 14, 2021 · Fundamentals

Why Overriding hashCode() Matters: Java HashSet Gotchas Explained

This article explains the purpose of Java's hashCode() and equals() methods, outlines the rules for overriding them, demonstrates common pitfalls with HashSet through a concrete code example, and clarifies why both methods must be overridden when using custom objects as HashMap keys.

CollectionsHashMapJava
0 likes · 6 min read
Why Overriding hashCode() Matters: Java HashSet Gotchas Explained
Senior Brother's Insights
Senior Brother's Insights
Mar 18, 2021 · Fundamentals

Why Overriding hashCode Is Required When You Override equals in Java

This article explains the relationship between Java's equals and hashCode methods, outlines their contractual requirements, shows how the default implementations work, demonstrates proper overrides with code examples, and provides practical guidelines for implementing robust hashCode functions to ensure correct behavior in hash‑based collections.

HashMapJavacoding guidelines
0 likes · 11 min read
Why Overriding hashCode Is Required When You Override equals in Java
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.

CollectionsJavaObject Equality
0 likes · 9 min read
Understanding equals() and hashCode() in Java: When They Matter
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.

CollisionData StructuresHashMap
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 StructuresHashMapJDK7
0 likes · 19 min read
Understanding Java HashMap: Implementation Principles, JDK7 Source Walkthrough, and Interview Insights
Programmer DD
Programmer DD
Aug 8, 2019 · Backend Development

Why Overriding hashCode and equals Is Critical: Avoid Memory Leaks and Bucket Chaos in Java

This article explains the contract between hashCode() and equals() in Java, shows the problems caused by violating it—such as incorrect behavior in HashMap/HashSet and memory leaks—and provides practical guidelines and code examples for implementing robust hashCode methods, including the use of Apache's HashCodeBuilder.

HashMapImmutable ObjectsJava
0 likes · 15 min read
Why Overriding hashCode and equals Is Critical: Avoid Memory Leaks and Bucket Chaos in Java
Java Backend Technology
Java Backend Technology
Jun 11, 2019 · Backend Development

Why Overriding equals Without hashCode Breaks Java Collections

This article explains the contract of equals and hashCode in Java, shows what goes wrong when only equals is overridden, provides a vivid house‑ownership analogy, and offers practical guidelines and code examples for correctly overriding both methods.

Backend DevelopmentCollectionsJava
0 likes · 5 min read
Why Overriding equals Without hashCode Breaks Java Collections
Java Captain
Java Captain
Nov 11, 2017 · Fundamentals

Understanding Java's equals() and hashCode() Methods and How to Override Them

This article explains the default implementations of Java's Object.equals() and Object.hashCode(), the required contracts for overriding them, demonstrates their behavior in the String class, and provides practical guidelines and example code for correctly overriding these methods in custom classes.

HashingOverrideString
0 likes · 11 min read
Understanding Java's equals() and hashCode() Methods and How to Override Them
Java Captain
Java Captain
Sep 28, 2017 · Backend Development

Four Java Optimization Techniques: Purposeful Optimization, Using Enums for Constants, Overriding equals(), and Leveraging Polymorphism

This article presents four practical Java optimization strategies—targeted performance tuning, replacing primitive constants with enums, correctly overriding the equals() method, and increasing the use of polymorphism—to improve system efficiency and code readability while highlighting when each technique should be applied.

EnumsJavaequals
0 likes · 18 min read
Four Java Optimization Techniques: Purposeful Optimization, Using Enums for Constants, Overriding equals(), and Leveraging Polymorphism