Browse by Topic

Popular

Latest

Latest Java Posts

A visual comparison of inheritance as a rigid tree structure and composition as a flexible set of connected blocks, illustrating the Java design decision.
Java

Java Inheritance vs Composition: How to Decide

Learn when to use inheritance vs composition in Java, with code examples, tradeoffs, and practical guidance for maintainable design.

inheritancecompositionobject-oriented designcode reuse
Diagram showing a Java class composed of other objects, illustrating has-a relationships
Java

Java Composition: Using Has-A Relationships Effectively

Learn how Java composition models has-a relationships, when to prefer it over inheritance, and how it improves maintainability and testability.

compositioninheritanceobject-oriented designcode reuse
Illustration of a Java collection being copied to prevent external mutation, showing two separate list boxes with an arrow indicating duplication.
Java

Defensive Copying in Java Collections: Protect Internal State

Use defensive copying in Java collections to protect internal state, avoid unintended mutation, and decide when copies are safer than unmodifiable views.

defensive copyingimmutable collectionsJava collectionsencapsulation
Diagram showing a mutable object being copied to protect internal state from external modification.
Java

Java Defensive Copy: When and How to Use It

Learn how defensive copying in Java protects mutable state, when to apply it, and how to avoid common pitfalls in constructors, getters, collections, arrays, and cloning.

defensive-copyjava-mutabilityobject-copyingjava-collections
A visual representation of an immutable Java class with locked fields and a shield symbol.
Java

Creating Immutable Classes in Java: A Practical Guide

Learn how to create immutable classes in Java with final fields, defensive copying, records, and builder patterns. Includes common pitfalls.

immutabilitydefensive copyingbuilder patternJava records
Illustration of a Java immutable object with final fields and defensive copying, symbolizing thread safety and data integrity.
Java

Java Immutable Object: Implementation and Use Cases

Learn how to design immutable objects in Java, including final fields, defensive copying, and records, and why they improve concurrency safety.

immutable objectsJava recordsdefensive copyingthread safety
A Java immutable class diagram showing final fields and no setters, with a lock icon representing thread safety.
Java

Java Immutable Class: Design and Implementation

Learn how to design immutable classes in Java: final fields, no setters, defensive copying, and why they simplify concurrency and caching.

immutable objectsJavaconcurrencyvalue objects
Diagram of an immutable Java object shown as a sealed box with a padlock, representing final fields that cannot be modified after construction.
Java

Java Immutability: Building Safe Immutable Classes

A practical guide to implementing immutable classes in Java: final fields, defensive copying, records, and the tradeoffs to weigh before making every class immutable.

Immutable ObjectsDefensive CopyingJava RecordsThread Safety
Comparison of Java HashMap and ConcurrentHashMap showing thread safety and concurrency handling
Java

Java HashMap vs ConcurrentHashMap: Choosing the Right Map for Concurrency

java hashmap vs concurrenthashmap: Compare Java HashMap and ConcurrentHashMap: thread safety, performance, null handling, and atomic operations to choose the right map...

JavaConcurrencyHashMapConcurrentHashMap
Illustration of a lock-free queue with multiple threads accessing nodes concurrently, representing Java's ConcurrentLinkedQueue.
Java

Using Java ConcurrentLinkedQueue for Lock-Free Thread-Safe Queues

Learn how to use Java's ConcurrentLinkedQueue for lock-free, thread-safe queue operations, including iteration behavior, performance tradeoffs, and common pitfalls.

ConcurrentLinkedQueueThread SafetyLock-FreeJava Concurrency