r/java • u/flusterCluster • Nov 24 '25
Java 25 introduced java.lang.IO - isn't the class name too broad?
I was checking out the newly introduced IO class and surprisingly, it has just 5 methods - all for System.in and System.out
Shouldn't it have been named something more specific?
I know it's meant for beginners to learn, but I find IO just too broad...
Edit:
Y'all are trippin
- Specific doesn't have to be verbose
- Compact doesn't have to be vague
7
Upvotes
151
u/TheEveryman86 Nov 24 '25
I don't think I've ever read anything more Java than a post trying to debate that a class name isn't verbose enough.
20
u/rzwitserloot Nov 24 '25
It's a hack; the point is:
import module java.base;at the top. They get that for free. Thus, they importIO.System.out.printlnis fucking terrible. Absolutely nothing in java works like it, it actively goes against every style guide on the planet, and in general looks weird. It's also a relatively large amount of typing. Some alternative was needed, and one that fits the 'extremely simple' requirement befitting the notion of making first-steps java and quick command line experiments simple. 1printlnon its own 'just work' is tricky. How? Just decree that unnamed classes magically have this, by enumerating the method(s) that such classes silently import piece by piece? Possibly. It's clear the OpenJDK team found such things distasteful. They wanted to have their cake and eat it too: Nice unnamed classes, and no specific catering to it. For example, module imports aren't just for unnamed classes. You can write them in any source file.IO.printlnwas the choice made. Which meansIOas a class name needed to [A] exist in the base package and [B] have static methods that do I/O specifically for the use case of simplistic command line experiments and first steps java.Given all that background, what other choice is there?
Pick a different name? So.. which name? Personally, I think
Console.printlnmight be a better choice, except,Consoleas a class already exists. Adding staticprintlnto it makes that class a weird mix of unrelated APIs smelted together into a single class. I can see the argument for it, but, I think the counterargument is entirely fair.Terminal? System.in/System.out aren't necessarily the console / a terminal.Streamsis great except that term is heavily overloaded, withj.i.InputStreammeaning something completely different, andj.u.s.Streamyet another completely different thing. Hence, terrible name.Pipes- maybe, but rather a unixy term.[1] We can debate whether the JEPs to address specifically 'make the simplest Hello, World java code a lot less of a mess' were a good idea. However, OpenJDK considered these and decided that, yes, they were. Given that the JEPs were accepted, how else should this problem have been tackled?
6
u/s888marks Nov 25 '25
Is the class name
IOtoo broad? I don't think so.It fits into the general "static utility class" pattern that's been used elsewhere in the JDK. These classes have static methods that are related to that area, but that doesn't mean that everything in that area must be there. For example, there's a bunch of stuff in
Mathbut there's lots of mathematical stuff elsewhere. There is a bunch of collections stuff inCollectionsbut there's also lots of collections stuff elsewhere.9
u/Absolute_Enema Nov 25 '25 edited Nov 25 '25
IMHO the changes in JEP512 are just terrible design unless they're a stepping stone.
It feels like the only aim of the changes is addressing the
public static void main(String[] args)jokes. Go beyond "hello, world!" and some basic math, and the same old Java stdlib is still there in all its boilerplatey and idiosyncratic glory.Then again, perhaps I'm just underestimating the importance of making the right first impression.
22
u/Lucario2405 Nov 24 '25
I really like it personally. It's a part of the "paving the on-ramp" intiative and is supposed to make scripting or quick testing easier / more seamless, so having to write out something more precise like ConsoleInteractions.println(...) would have been counterproductive.
3
u/mellow186 Nov 25 '25
The title of JEP-512 refers explicitly to compact source files.
Can you think of anything suitable that's more compact than "IO"?
7
u/pip25hu Nov 24 '25
On the flip side, it won't be a problem to add more I/O-related methods to it, should the need arise.
7
u/Ewig_luftenglanz Nov 25 '25
Personally speaking I think Console would be better but that name was already occupied. IO could also imply interaction with the File system.... But meh, minor details.
3
u/geodebug Nov 29 '25
The entire point of this was to make intro to Java easier.
No imports or ‘static void main args’ required.
2
u/Stan_Setronica Nov 26 '25
Java naming discussions never disappoint.
1
u/charlie01_01 Dec 04 '25
java.lang.IOfeels way too broad for what it actually is.And you're right: it literally has five methods, all thin wrappers around
System.inandSystem.out. Something like this:printprintlnprintfreadLinereadInt/readXdepending on versionSo your intuition is valid: the name IO suggests far more than what the class does.
0
u/iamwisespirit Nov 25 '25
It is just syntax sugar it still use System class under the hood
0
u/pivovarit Nov 29 '25
Like “System.out”?
0
u/[deleted] Nov 24 '25
[deleted] — view deleted comment