Tag

autoboxing

0 views collected around this technical thread.

DaTaobao Tech
DaTaobao Tech
Aug 23, 2024 · Fundamentals

Common Java Pitfalls and Their Solutions

The article outlines frequent Java pitfalls—including BigDecimal precision loss, immutable lists from Arrays.asList, double division by zero returning Infinity, null values in switch statements, stream filters mutating original objects, and autoboxing nulls causing NullPointerExceptions—and provides clear explanations and practical fixes to enhance code reliability.

Arrays.asListBigDecimalJava
0 likes · 5 min read
Common Java Pitfalls and Their Solutions
IT Services Circle
IT Services Circle
Jul 16, 2022 · Fundamentals

Common Java Pitfalls: Equality, Objects.equals, BigDecimal, Streams, Autoboxing, and String Replacement

This article explains six frequent Java pitfalls—including misuse of the == operator with Integer, subtle bugs in Objects.equals, precision loss with BigDecimal constructors, reference sharing in Stream.filter, NullPointerExceptions from autounboxing, and differences between replace, replaceAll, and replaceFirst—providing code examples and best‑practice recommendations.

BigDecimalEqualityJava
0 likes · 12 min read
Common Java Pitfalls: Equality, Objects.equals, BigDecimal, Streams, Autoboxing, and String Replacement
IT Xianyu
IT Xianyu
Jan 24, 2022 · Fundamentals

Why does Java evaluate 1000==1000 as false while 100==100 evaluates to true?

The article explains that Java's Integer caching for values between -128 and 127 causes small integer objects to be shared, making == true for 100, whereas larger integers like 1000 are distinct objects, so == returns false, and it demonstrates this behavior with code and reflection examples.

CachingIntegerJava
0 likes · 4 min read
Why does Java evaluate 1000==1000 as false while 100==100 evaluates to true?
Top Architect
Top Architect
Jan 2, 2022 · Backend Development

Understanding Java Integer Caching: Why 1000 == 1000 Is False but 100 == 100 Is True

The article explains that Java's Integer objects use an internal cache for values between -128 and 127, causing equality checks with the == operator to return true for small numbers like 100 but false for larger numbers like 1000, and demonstrates how to inspect and manipulate this cache via reflection.

CachingIntegerJava
0 likes · 5 min read
Understanding Java Integer Caching: Why 1000 == 1000 Is False but 100 == 100 Is True
Full-Stack Internet Architecture
Full-Stack Internet Architecture
Dec 29, 2020 · Fundamentals

Understanding Java Syntactic Sugar: Generics, Autoboxing, Enums, Inner Classes, Varargs and More

This article explains the concept of syntactic sugar in Java, covering generics, autoboxing/unboxing, enums, inner classes, variable‑length arguments, enhanced for‑loops, switch on strings, conditional compilation, assertions, try‑with‑resources, and string concatenation, with code examples and byte‑code analysis.

Inner ClassesJavaVarargs
0 likes · 17 min read
Understanding Java Syntactic Sugar: Generics, Autoboxing, Enums, Inner Classes, Varargs and More
Full-Stack Internet Architecture
Full-Stack Internet Architecture
Dec 9, 2020 · Fundamentals

Understanding Java Syntactic Sugar: Generics, Autoboxing, Enums, and More

This article explains the concept of syntactic sugar in Java, covering generics, autoboxing/unboxing, enums, inner classes, var‑args, enhanced for‑loops, switch on strings, conditional compilation, assertions, try‑with‑resources, and string concatenation, while showing the underlying bytecode transformations.

Inner ClassesJavaautoboxing
0 likes · 18 min read
Understanding Java Syntactic Sugar: Generics, Autoboxing, Enums, and More
Full-Stack Internet Architecture
Full-Stack Internet Architecture
Nov 10, 2020 · Fundamentals

Understanding Java Integer Caching and the Pitfalls of Using == vs equals

This article explains Java's Integer caching mechanism, why using == on wrapper objects can be misleading outside the -128 to 127 range, shows how to control the cache size with JVM options, and demonstrates bytecode inspection with javap to reveal the underlying valueOf calls.

JVM optionsJavaJavap
0 likes · 5 min read
Understanding Java Integer Caching and the Pitfalls of Using == vs equals
Full-Stack Internet Architecture
Full-Stack Internet Architecture
Jul 16, 2020 · Backend Development

Understanding Java Integer Caching and Autoboxing: Why == Fails and How to Use equals

This article explains Java's Integer caching mechanism, why using == on Integer objects can give unexpected results outside the -128 to 127 range, how the Integer.valueOf method and the IntegerCache work, and how to inspect the behavior with javap and JVM options.

IntegerCacheJavaJavap
0 likes · 6 min read
Understanding Java Integer Caching and Autoboxing: Why == Fails and How to Use equals
macrozheng
macrozheng
May 22, 2020 · Backend Development

Why Java’s Ternary Operator Can Trigger NullPointerException with Autoboxing

This article explains how the combination of Java's ternary operator and automatic boxing/unboxing can unintentionally cause a NullPointerException, demonstrates the issue with decompiled code, and provides a safe coding pattern to avoid the runtime error.

JavaNullPointerExceptionautoboxing
0 likes · 7 min read
Why Java’s Ternary Operator Can Trigger NullPointerException with Autoboxing
Selected Java Interview Questions
Selected Java Interview Questions
Apr 29, 2020 · Fundamentals

Understanding Java Parameter Passing, Autoboxing, and Swapping Integer Values

This article explains why swapping Integer objects using a simple assignment fails in Java, covering formal vs. actual parameters, value versus reference passing, autoboxing mechanics, the Integer cache, and a reflective workaround that avoids the cache to correctly exchange values.

InterviewJavaautoboxing
0 likes · 9 min read
Understanding Java Parameter Passing, Autoboxing, and Swapping Integer Values
Full-Stack Internet Architecture
Full-Stack Internet Architecture
Mar 11, 2020 · Fundamentals

Understanding Java Integer Caching and Autoboxing: When == Can Mislead

This article explains Java's Integer caching mechanism, why using == to compare wrapper objects can produce unexpected results, how the IntegerCache works, how to adjust its range with JVM options, and demonstrates the behavior through code examples and javap decompilation.

JavaJavapautoboxing
0 likes · 7 min read
Understanding Java Integer Caching and Autoboxing: When == Can Mislead
Full-Stack Internet Architecture
Full-Stack Internet Architecture
Sep 24, 2019 · Fundamentals

Understanding Java Integer Caching and Autoboxing: Interview Questions Explained

This article explains Java's Integer autoboxing and caching mechanism through three interview code examples, detailing why comparisons of certain Integer objects yield true or false, how the IntegerCache works, and how Java's pass‑by‑value semantics affect object references.

Interview QuestionsJavaautoboxing
0 likes · 4 min read
Understanding Java Integer Caching and Autoboxing: Interview Questions Explained
Java Captain
Java Captain
Dec 12, 2017 · Fundamentals

Understanding Integer and String Comparison in Java

This article explains Java's Integer and String comparison quirks, detailing how autoboxing caches values between -128 and 127, why '==' behaves differently for objects versus primitives, and demonstrates these concepts with clear code examples and explanations.

CachingIntegerJava
0 likes · 7 min read
Understanding Integer and String Comparison in Java
Beike Product & Technology
Beike Product & Technology
Aug 15, 2017 · Mobile Development

Optimizing Android Memory Usage by Avoiding Autoboxing in Long Objects

This article discusses memory optimization in Android apps by addressing excessive object allocations caused by autoboxing Long values, leading to performance issues during feed scrolling. The solution involves implementing a custom data structure to reduce memory usage and improve application responsiveness.

Android OptimizationData StructuresMobile Development
0 likes · 8 min read
Optimizing Android Memory Usage by Avoiding Autoboxing in Long Objects
Qunar Tech Salon
Qunar Tech Salon
Mar 21, 2015 · Fundamentals

Understanding Null in Java: Causes, Behaviors, and Best Practices

This article explains the role of the null keyword in Java, its default value for reference types, common pitfalls such as NullPointerException caused by autoboxing, improper primitive assignments, instanceof checks, static method calls on null references, and safe handling techniques to write null‑safe code.

Best PracticesJavaNULL
0 likes · 12 min read
Understanding Null in Java: Causes, Behaviors, and Best Practices