01 / 01

Merged to OpenJDK master

JEP 401: Value Objects (Preview)

OpenJDK

2025

02

What are Value Objects?

A new programming model for the JVM

Understanding Value Objects

  • 01
    Identity-free objects Value objects have no inherent identity — two instances with the same field values are considered equal
  • 02
    Immutable by design Once created, value objects cannot be modified, ensuring thread safety and predictable behavior
  • 03
    Optimized memory usage The JVM can optimize value objects by eliminating object headers and enabling stack allocation
04

The Preview Release

Key features and syntax

Core Features of JEP 401

code

Value Keyword

New 'value' modifier for declaring value classes

speed

Performance Gains

Reduced memory footprint and improved runtime performance

security

Thread Safety

Immutable nature ensures safe concurrent access

auto_awesome

Seamless Integration

Works with existing Java code and libraries

Value Object Syntax Example

Point.java
public value record Point(int x, int y) {
    // Automatic equals, hashCode, toString
}

// Usage
Point p1 = new Point(10, 20);
Point p2 = new Point(10, 20);

System.out.println(p1.equals(p2)); // true

Declaring and using value objects in Java

Traditional Classes vs Value Objects

Traditional Classes
  • Reference equality by default
  • Object header overhead (16+ bytes)
  • Heap allocation required
  • Synchronization needed for threads
Value Objects Recommended
  • Value equality by default
  • Minimal overhead (no header)
  • Stack allocation possible
  • Thread-safe by design

Thank You

JEP 401 marks a significant milestone in Java's evolution

https://github.com/openjdk/jdk/pull/31120
Made with AirSlide
𝕏 in