A record is a special class that acts as a transparent carrier for immutable data. It automatically produces constructors, accessors, equals(), hashCode(), and toString().
Java Records
Model immutable data concisely with zero boilerplate in Java 14+.
Key Takeaways: Java Records
Mastering Java Records helps you write clean and reliable Java code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.
Java Records Code Example
Javapublic record Point(int x, int y) {}
public class Main {
public static void main(String[] args) {
Point p = new Point(10, 20);
System.out.println(p);
System.out.println("X coordinate: " + p.x());
}
}
Output
Point[x=10, y=20] X coordinate: 10
Run this example on your own computer. The "Get Started" lesson shows how to set it up.
Finished this lesson?
Mark it complete to track your progress.
Stuck on something?
Ask the community in the CodesInTech forum.
Need a developer?
Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.
Explore Our Services