Skip to content(if available)orjump to list(if available)

Public static void main(String[] args) is dead

abhiyerra

I learned to read line as the following in Java 1.2 so the Scanner class is new to me. :p

  BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
  String input = in.readLine();

adgjlsfhk1

It's amazing that ~30 years on, Java is finally becoming a not horrible programming language.

willvarfar

I'm someone who wrote a lot of 'raw' Java and C++ without frameworks, which meant there was a lot less boilerplate and indirection etc. And for me, the big usability bump came about 10 years ago, around the same time for both Java and C++, when they started supporting lambda functions. I started passing code into algorithms and, although it sounds quite complicated, it simplified my programs substantially.

voidfunc

Meanwhile some languages like Python still suck 30 years later.

bigstrat2003

Java was never a horrible programming language. The hate is wildly overblown.

vincnetas

Most likely you have not seen horrible languages or your bar for being not horrible is quite high.

yohannesk

Why not abstract away the public static void main(String[] args) method with a top-level statement paradigm, similar to C#'s entry point simplification, to reduce boilerplate and enhance code conciseness?

mhh__

Why should the entry point be a random special case? You're already admitting at this point that OOP is flawed so you might as well just have the balls to design a proper alternative (rather than a kludge)

samlinnfer

JEP 445: Unnamed Classes and Instance Main Methods

Released in Java 21

https://openjdk.org/jeps/445

rerdavies

[delayed]

furyofantares

We got there just after we got the ability to legitimately create useful small programs without understanding any of the thousands of lines of code.

cynicalsecurity

Why did it suck exactly?

TZubiri

Ugly? Sure. But isn't this the identity of Java? Taken away for almost no gain, there's literally no real issue stemming from requiring a verbose incantation to write a main routine, this is something you learn like day 1 on learning java, and it's something you write once in a blue moon, like 0.001% of the code you are going to write.

It reminds me of the attempt at removing Richard Stallman from the FSF, yeah, you could do that and fix a problem, but then what you are left with isn't really the same thing as it was before, it's now actually the same soulless thing as the rest of the competing things.

Saving grace is that obviously, you can still recite the incantation, it's not like public static void main(String[] args) is gone, just that you can skip it.

another_twist

This is not a prank right ? Is it really gone ?

throwmeaway222

Might come back to Java

Panzerschrek

So, Java now supports free functions (not associated with some class). Or not really yet?

ninjin

If so, are we observing a move towards Universal Suffrage in the Kingdom of the Nouns? [1]

[1]: https://steve-yegge.blogspot.com/2006/03/execution-in-kingdo...

BinaryRage

No, these are just default imports. Module import declarations are in for JDK 25 to make this kind of thing even easier: https://openjdk.org/jeps/511

vincnetas

I think all functions are associated with some class. But these classes sometimes are hidden from you and you don't need to know about them. Does that help you? What for would you use true free functions?

throwaway47461

> What for would you use true free functions?

The same things people use free functions for in any other programming language.

rerdavies

[delayed]

TZubiri

Presumably these exist in a Main.java file and the java class is implied. Similarly the string params are also implied, and the non param main() function is just an alias or a wrapper for main(String).

It's just syntactic sugar.