I have seen mentions of new classes and methods, like this, for interacting with a console in a Java app.
Yes, new console methods are being previewed in Java 24 (& Java 23).
The existing Console
class, and a new IO
class, offer print
, println
, & readln
methods.
The old System.out.println ( "Hello world!" )
is supplanted by the new IO.println ( "Hello world!" )
.
Yes, there is a series of JEPs adding features related to the console.
This series is part of the Paving the On-Ramp effort in recent years to make Java easier for beginner students.
java.io.IO
If successful, this series of JEPs would add a new class, java.io.IO
. This class offers these methods:
static void print ( Object obj )
static void println ( Object obj )
static String readln ( String prompt )
Notice that these methods are static
. So we can use them without instantiating an object.
So the familiar System.out.println ( "Hello world!" );
becomes:
import java.io.IO;
…
IO.println ( "Hello world!" );
Or, be even more brief with a static import
.
import static java.io.IO.println;
…
println ( "Hello world!" );
java.io.Console
These java.io.IO
methods are implemented by calling upon the Console
object returned from System.console()
. So that Console
class gains new methods, with the same signatures.
Caveat: These are preview features, subject to change or removal.
Try these out in an early-access build of Java 24 based on the OpenJDK codebase. See the early-access Javadoc for Java 24.