Static Members & Records in Java
From the Java cheat sheet · Classes & Records · verified Jul 2026
Static Members & Records
Class-level members and concise immutable data carriers.
java
// Quick Reference
static int count = 0; // shared across all instances
static final double PI = 3.14; // constant
record Point(int x, int y) {} // immutable data class💡 static members belong to the class itself and are shared by every instance.
⚡ Records auto-generate the constructor, accessors, equals, hashCode, and toString.
📌 Record accessors are named after the field: point.x(), not point.getX().
🟢 Records are immutable and final - ideal for DTOs, keys, and value objects.
staticrecords