Skip Top Navigation Bar

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:

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:

And most devastating:

Teachers were left with not great responses to these statements. I would maybe say:

Or an attempt to explain things:

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!

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!

Let's look deeper at this statement:

x instanceof byte b

There are three parts to pattern matching:

  1. 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

  2. Creates a variable b.

    byte b

  3. 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

Learn more on Pattern Matching: Pattern Matching in Java