JDK-8355664 : Creating I/O API's in JDK to simplify DSA coding and core java learning
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.io
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2025-04-26
  • Updated: 2025-04-28
  • Resolved: 2025-04-28
Related Reports
Duplicate :  
Description
A DESCRIPTION OF THE PROBLEM :
As a student/new learner/experienced programmer etc., I have to use some common code to perform I/O operations while coding DSA questions which has some concerns in my perspective:

1. It takes new java programmers to learn it. Eg: What and how Scanner and other Java I/O api's works.
2. I have to use SOUT everytime to print the output along with for loops sometimes for List of objects.

While the same thing takes lesser time to learn it with Python which has been mostly adopted by new comers from the past few years becuase of its simplicity with i/o required to learn in the starting phase of developer /student career.

Can we add new API's like Python in java to simplify I/O process?

Eg: Python code

name = input("Enter your name: ")
print("Hello, " + name + "!")

age = input("Enter your age: ")
age = int(age) # Convert to integer
print("You are", age, "years old.")

In Java can we define input() and output() function in wrapper classes to make it more simple to read from console? Then I don't have to use Scanner APIs for Input and SOUT for ouput operation in my java DSA code.

Similarly we could also introduce input() and output() methods with array and collection classes to make java easy to use and understand.

One could create its own API's and use it while learning DSA/Core java but I believe this small change will really help us.

I am happy to share more insights into this idea and can contribute to it if required.




Comments
JEP 512 will add IO.println and IO.readln which are close equivalents to Python's print() and input() functions. I'm closing this Enhancement request as a duplicate of the JEP 512 issue. Note that we are considering conversions (e.g., from string to integer) completely separately from the IO functions. This is still a work in progress. The equivalent to Python's int() conversion is more-or-less Integer.parseInt(inputString.strip()) in Java. Note that this throws a NumberFormatException if conversion fails, rather similar to Python's int() which throws ValueError. This could undoubtedly be made shorter or more friendly. But this raises a whole bunch of questions about error handling. Certainly the simplest thing is to ignore error handling and let the conversion throw an unhandled exception. Alternatives include using pattern matching (an evolving language feature) or returning an Optional. Both require the caller to perform a conditional check to determine whether the conversion was successful. Discussion on this topic continues.
28-04-2025

See https://openjdk.org/jeps/512, and then the Java equivalent of that python code will be: var name = IO.readln("Enter your name:"); IO.println("Hello, " + name + "!"); var ageString = IO.readln("Enter your age:"); // Or var age = Integer.parseInt(ageString); var age = new Integer(ageString); // Note: we will un-deprecate this once valhalla arrives IO.println("You are " + age + " years old.");
28-04-2025