Java 25, released in September 2025, is a Long-Term Support (LTS) version. It includes many language improvements, performance tweaks, and API additions. Some features are stable, some are preview/incubator.
Here are some of the major changes:
-
Compact source files & instance main methods (JEP 512)
You can now write simpler Java programs without declaring a class explicitly just to definemain
. Also, you can usevoid main()
withoutstatic
/public
etc, in “compact” source files. -
Flexible constructor bodies (JEP 513 – Final)
Earlier, Java requiredsuper(...)
orthis(...)
to be the very first statement in a constructor. Now you can write code (validation, computing, etc.) before callingsuper(...)
. This helps avoid redundancy or awkward helper methods. -
Primitive types in patterns (instanceof, switch) – JEP 507 (Preview)
Pattern matching has become more powerful: primitive types can be “matched” ininstanceof
orswitch
. -
Module import declarations – JEP 511 (Preview)
You can now import modules viaimport module
, which helps modular projects and reduces boilerplate when referencing multiple types from the same module. -
Scoped values (JEP 506 – Final)
A lightweight alternative toThreadLocal
for sharing immutable data across threads (especially with virtual threads). -
Performance Improvements & JVM Enhancements
-
Compact Object Headers: shrink object header memory footprint.
-
Generational Shenandoah GC is now productive (more mature/usable) mode.
-
Ahead-of-Time (AOT) method profiling & improved command-line ergonomics.
-
More enhancements in Java Flight Recorder (JFR): CPU time profiling, method timing/tracing, cooperative sampling.
-
-
Removed / Deprecated Features
-
32-bit x86 port removed.
-
Some APIs deprecated; see release notes for full list. Oracle
-
To make this concrete, here are code snippets showing some of the new features in Java 25.
1. Compact Source File & Instance Main Method
In older Java you would write:
Now with compact source file in Java 25:
You may also omit String[] args
if you don’t need command line arguments.
2. Flexible Constructor Bodies
Old restriction: a constructor had to call super(...)
or this(...)
as the first statement.
New in Java 25:
3. Primitive Types in Patterns (Preview)
Or in switch:
These features are still preview, so you need to enable preview mode when compiling and running.
What You Need To Take Care Of
-
Many features are preview or incubator: to use them you’ll need compiler flags like
--enable-preview
. -
Compatibility: removed 32-bit x86; deprecated APIs may be removed in future. If your application needs to support older/legacy platforms, test carefully.
-
Some features, like compact source files, have limitations (e.g. default package, tooling support, IDE support) which may affect larger or enterprise codebases.
Why This Matters
Here are a few benefits and scenarios where the new features help:
-
Faster prototyping, teaching, scripts less boilerplate means students or small utilities can get to “Hello World” faster.
-
Cleaner code for validation/initialization logic flexible constructors let you avoid helper methods or redundant checks.
-
Better performance reduced memory use, better GC, quicker startup, improved profiling & observability.
-
Modular codebases & AI/modern workloads features like primitive types in patterns, scoped values, module import declarations help write cleaner, more expressive code for modern architectures.
Conclusion
Java 25 is a solid release, especially for those coming from Java 21 or earlier. It continues the trend of making Java less verbose in boilerplate, improving performance, and giving developers more expressive tools, while maintaining compatibility and introducing new performance-oriented JVM features.
If you're using Java 21 (or earlier), moving to Java 25 means you’ll benefit from:
-
simpler syntax for small programs
-
safer, more flexible constructors
-
better memory, GC, and startup performance
-
access to preview features if you’re willing to try and stay up to date