Java Systems ProgrammingPerformance EngineeringCode OptimizationMemory Optimization 1 min read

Java 28 Introduces Value Objects as a Preview Feature Under Project Valhalla

JDK 28 introduces identity-free Value Objects as a preview feature, allowing developers to optimize memory layout and performance for data-oriented programming.

JEP 401 targets Value Objects for inclusion in JDK 28 as a preview feature.

This addition introduces a new category of class lacking identity. You can use them for data-oriented programming. Traditional object-oriented patterns in Java carry overhead because every instance includes a header for synchronization and memory overhead. By defining a class as a Value Object, you signal that the class does not require identity. The Java Virtual Machine then optimizes memory layout and performance by flattening these objects into memory structures where appropriate.

Value Objects are part of Project Valhalla. They act as identity-free types. You can write code that behaves like primitives in terms of memory usage while retaining the structure of object-oriented design, which improves efficiency by aligning the language more closely with modern hardware memory hierarchies.

The feature is disabled by default. You must explicitly enable preview features during both compilation and execution to experiment with Value Objects in JDK 28. This preview stage lets you provide feedback on the implementation and usage before finalization in a future release.