What's New with Java 25?
It's time to celebrate the release of the newest version of Java... Java 25! Java 25 was released September 16, 2025.
Java updates every 3 months, with the next update being released in March 2026.
There are three features teachers should be aware of:
- Flexible Constructor Bodies
- Compact Source Files and Instance Main Methods
- In preview, Primitive Types in Patterns,
instanceof
, and switch
Compact Source Files and Instance Main Methods
This feature makes starting with Java so much easier.
Most students experience writing their first program as follows:
public class FirstProgram {
public static void main(String[] args) {
System.out.println("This is my first program!");
}
}
There is so much in this code segment that is important for large programs, but not necessary for smaller programs that are written when you are just starting out learning programming. Students see this code and they start to think some of the following:
- Wow! What is all of this?
- I don't think I can do this
- What does public mean? static?
- What's String[] args?
- Do I have to memorize all this?
- Programming is hard!
- This is a LOT!
And most devastating:
- I don't think I can do this!
Teachers were left with not great responses to these statements. I would maybe say:
- "Just type it in..."
- "I'll explain it later..."
Or an attempt to explain things:
- "Well, everything in Java is written in a class and the main is where the compiler starts."
Ugh! So unsatisfying.
With this feature, students can start their program by simply writing:
void main() {
//body
}
Not a lot to have to explain there.
The New IO Class
Additionally, I always wanted my students to recognize the pattern of calling a most methods as: <object>.<methodName>()
. Or <Classname>.<methodname>();
Unfortunatly, System.out.println("This is my first program!");
breaks this simple pattern by having System.out
. Another complexity to have to explain out
.
This feature includes a new class called IO
. The IO
class contain static
methods for input and output.
Method |
Method Description |
print(Object obj) |
Writes a string representation of obj to the console. Does not move to the next line after the string representation of obj is printed to the console. Any new calls to print will continue directly after what was printed. |
println() |
Stands for print line. Stops printing on the current line and moves to the next line. |
println(Object obj) |
Writes a string representation of obj to the console and moves to the next line. Any new calls to print or println will start on the next line. |
readln() |
Reads a single line of text from the console.
|
readln(String prompt) |
Writes prompt to the screen as if calling print . Then, reads a single line of text from the console. |
Note that readln
reads values as String
. Any non-String
values will need to be properly parsed. But, no more need for Scanner
class.
Learn more on input and output: Console Input and Output
Automatic Import
Finally, this feature includes an automatic import of java.base
, which includes java.util
. This means you no longer need to import statements to use ArrayList
. Many compilers will delete the import if you attempt to include it. Be sure to warn your students of this change.
Flexible Constructor Bodies
Flexible constructor bodies allow us to add statements prior to the call to super()
and this()
in the constructor.
Try it Yourself!
- Run the code. Note, the difference in cook time. Why is that?
- Change the instantiation of the cake to have a cook time of
35
minutes and re-run the program code. Note how the output changes.
- Insert a statement before the call to
super
to update ovenTime
to be at least 30
minutes if it is less than 30
and remove the validate
method.
- Run the code with both
20
and 35
for ovenTime
. The results should be the same as the original code.
Primitive Types in Patterns instanceof
This feature is in preview in Java 25. To use it you will need to turn on preview features. It is part of a series of Pattern Matching features. Pattern matching works to make code more readable.
In the past, instanceof
is used to check the type of a reference variable. This feature would allow us to check the type of a primitive variable.
Try it Yourself!
- Run the code below.
- Change the value of x to 100000 and run the code.
Let's look deeper at this statement:
x instanceof byte b
There are three parts to pattern matching:
Checks to see if x
is of type byte
. Really, what we are checking is can the value of x
be assigned to a byte
without any loss of data.
x instanceof byte
Creates a variable b
.
byte b
Assigns b
the value of x
. Essentially, if the value of x
can be assigned to a byte
without any loss of data, byte b = (byte)x
.
x instanceof byte b
Primitive Types in Patterns switch
The second part of this features is expanding the types that can be used in a switch statement or expressions to include additional primitive values, such as boolean
.
Try it Yourself
- Run the code.
- Notice there is no need for a default statement here since we have expressed the full range of
boolean
values: true
and false
.
- Modify the code to assign x to an even value and re-run the code.
Learn more on Pattern Matching: Pattern Matching in Java