Home › coding › java › java records

Java Records — Free Java Tutorial

Learn Java Records in Java with a free, beginner-friendly tutorial, examples and practice for Indian students on Syllab.in.

✓ 100% Free ✓ No Login Needed ✓ NCERT / CBSE Aligned ✓ Download as PDF

TL;DR: Learn Java Records in Java with a free, beginner-friendly tutorial, examples and practice for Indian students on Syllab.in.

Written & reviewed by the Syllab.in Academic Team (CBSE/NCERT subject experts) · Updated Jul 14, 2026

🤖 Stuck on any question? Ask Syllab's free AI Tutor for a step-by-step explanation — instant, unlimited, no login.

Java Records in Java

Records (Java 16+) are concise immutable data classes. A single record declaration automatically generates: constructor, private final fields, getters (accessor methods), equals(), hashCode(), and toString().

Records are immutable — all fields are final and set at construction time. They are ideal for DTOs (Data Transfer Objects), value objects, and data carriers.

Record components are accessed with component-name() methods (not getXxx()): for record Point(int x, int y), use point.x() and point.y().

Records can have: compact constructors (for validation), additional methods, static fields, and can implement interfaces. They cannot extend classes (they implicitly extend Record).

Java Records — Syntax

// Define a record
record Point(int x, int y) {}

// Automatically has:
// - public Point(int x, int y) constructor
// - public int x(), public int y() accessors
// - equals(), hashCode(), toString()

Point p = new Point(3, 4);
p.x();         // 3
p.y();         // 4
p.toString();  // "Point[x=3, y=

Learn Java Records step by step with Syllab's free interactive Java tutorial — runnable code examples, practice exercises and instant AI feedback, all free with no signup. Explore the full Java course →

Explore:

  • Syllabus
  • Practice
  • Mock Tests
  • NCERT Solutions
  • Coding
  • GK Quiz
  • Career Predictor
  • AI Tutor
  • Live Quiz
  • Doubt Solver
  • Microlearning
  • Free Alternatives
  • Kids Zone
  • Study Room
  • Calculators
  • Worksheets

Syllab.in — Free learning for Indian students, Class 1–12