K5kC LogoK5kC | Code & More
Computer Science
AlgorithmsJavaProgramming LanguagesDatabaseSystem Design
Problems
Blind 75Algo KernelDifficulty: EasyDifficulty: MediumDifficulty: Hard
Videos
Projects
AndroidData ScienceComputer VisionSimulations
Tools
UUID GeneratorCode Formatter
Search⌘K
Computer Science
Java
Core Java
Object-Oriented Programming in Java
Java Immutable Classes

Core Java

Overview
Encapsulation in Java: Hiding Data and Protecting Invariants
Encapsulation vs AbstractionImmutable ClassesRecords
Computer Science
Java
Core Java
Object-Oriented Programming in Java
Java Immutable Classes

Java Immutable Classes

  • What is an Immutable Class?
  • Rules for Designing an Immutable Class
  • Why final Alone Isn't Enough
  • Worked Example — ImmutablePerson
  • The Getter Leak — Why Rule 5 Is Easy to Get Half-Right
  • Unsafe Publication During Construction
  • A Fuller Example — a Mutable Map Field
  • Effectively Immutable vs Truly Immutable
  • Why Bother — What Immutability Buys You
  • Immutable Classes in JDK
  • Common Gotcha: BigDecimal / BigInteger "Silent No-Op" Bug
  • Records (Java 16+) — The Modern Shortcut
  • Updating an Immutable Object: the withX Pattern
← PreviousJava Encapsulation vs AbstractionNext →Java Records
PrivacyDisclaimerReport an IssueAbout

© 2026 K5kC | Code & More. All rights reserved.

चरैवेति चरैवेति | Keep moving on