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

84 charles_irl 60 9/16/2025, 4:42:18 AM mccue.dev ↗

Comments (60)

crystal_revenge · 27m ago
One thing I'll miss about this was the way this arcane writing increasingly made sense over time as you became a better programmer.

I learned Java only after Python and I remember being not quite familiar with types so even the 'void' and 'String[]' where a bit mysterious. After learning basic types that part made sense. Then you start learning about Classes and objects, and you understood that main is a static method of this class Main that must be required somehow. As you dive deeper you start learning when this class is called. In a weird way what started as complete, unknowable boiler plate slowly evolved into something sensible as you began to understand the language better. I have no doubt that seasoned Java devs see a lot more in that invocation that I do.

Good riddance though!

panza · 6m ago
Yeah, I agree with this sentiment. The boilerplate was oddly helpful when I was starting out.
rottc0dd · 1m ago
From my previous comment in hn:

As a java guy and think python is weird, I don't think this sucks.

But, I also agree that can serve as terrible intro to programming if you start programming right away without understanding the basics of abstractions. But, often when we have tools either designed for a purpose in mind or a dominant paridigm or reaction to existing set of tooling, this can result in understandable yet extreme abstractions.

Java is designed with OOP in mind and it kind of makes sense to have the user to think in terms of lego blocks of interfaces. Every method or class needs to have clear understanding of its users.

public - software handle is for all users

protected - software handle for current and extending classes

default - software is exposed to current package

private - software is restricted to be used in current class alone and nowhere else

So, the beginning of java programming starts with interface exposed to the user or other programmers. Is it weird and extreme. Yes. At least, it is consistent.

abhiyerra · 45m ago
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();
riffraff · 11m ago
Yep, same for me, it's been a long time since I did java and while the publicstaticvoidmain mantra felt familiar I was a bit confused by the Scanner thing and couldn't say why.
samlinnfer · 44m ago
JEP 445: Unnamed Classes and Instance Main Methods

Released in Java 21

https://openjdk.org/jeps/445

rerdavies · 30m ago
:-) So not even remotely dead.
kazinator · 2m ago
[delayed]
keithasaurus · 1m ago
could java please also learn that stand-alone functions are cleaner than static methods? even if it's just syntax sugar...
beginnings · 42s ago
but I need my public static void main arg arg arg
Peteragain · 17m ago
What we seem to have forgotten is just how c like java was compared to other programming languages being advocated at the time. Objects made sense (remember Ada?) but c++ was a mess. Java was a breath of fresh air with lots of c legacy.
vkazanov · 2m ago
Oh, I do remember the narrative: OOP is amazing but Cpp is not pure OOP let's make the OOPiest language possible.

I also remember casts all over the place in Java because polymorphism wasn't OOP enough.

And then lambdas and functions were not OOP enough to be first class values and that's why we needed numerous "verb-classes" everywhere.

And of course printf() is not OOP enough...

giveita · 3m ago
Looks like C# to me
adgjlsfhk1 · 43m ago
It's amazing that ~30 years on, Java is finally becoming a not horrible programming language.
bigstrat2003 · 34m ago
Java was never a horrible programming language. The hate is wildly overblown.
userbinator · 10m ago
The culture of insane overengineering around it is the problem, not the language itself.
echohack5 · 2m ago
In 2012 managing the JVM was a nightmare. Java is fine now.
pjmlp · 12m ago
In fact, it was welcomed in open arms even being originally interpreted, because writing portable C or C++ code in 1996 was still a mess, even across UNIX flavours.

On my university no one got Sun's marketing money in 1998, yet the distributed systems, compilers design, and graphics programming, all adopted Java as the language for new teaching materials, as it sorted out several problem with the assignments.

TZubiri · 27m ago
Only bad experience I remember from Java was the int/Integer primitive/object issue and boxing.

Also of course the misuse and overuse of classes when designing systems, but the complexity at design time is also the counterpart of the ease of use of well designed APIs. I remember using an IDE to write some code and it skipped the whole documentation and run/compile error phase, I could just cast mismatching types as needed.

Probably C# and Swift/Objective C would only be above Java as top languages, being actually funded by paying customers instead of used by companies that depend on volunteer developed open source software and end-users that equate paying for software with evilness.

voidfunc · 18m ago
Being forced to use anonymous classes to simulate lambdas prior to 8 was the biggest source of annoying boiler plate IMO and was genuinely a bad experience in sufficiently complex or large code bases.

Everything beyond 8 has been nice to have but 8 was the big one.

tetha · 6m ago
> Only bad experience I remember from Java was the int/Integer primitive/object issue and boxing.

Heh, I once had to work in a code base that used an `Integer premiumDefenseLevel`. It contained the level of premium defense a player had purchased, or null if the player didn't have any levels of premium defense purchased in the recent times.

This was in fact annoying to remove, because a 0 after a 1 was treated differently than a null some time for advertisement reasons: Someone who had bought premium defense in the past is more likely to re-buy than someone who didn't, so they are pestered with ads. But it eventually turned into a neat little domain object.

nananana9 · 5m ago
> the int/Integer primitive/object issue and boxing.

That's a deal-breaker. If you can't tie together a few values in a record/struct without being forced to box them/heap allocate them, the language will never be used anywhere where you even remotely care about performance.

This is not a difficult problem to solve - C# did it in a very elegant way with structs, and as a direct result, probably for half of all videogames written today, the gameplay portion is written in C#.

willvarfar · 29m ago
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 boon 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. Before that syntactic sugar gave the affordance I hadn't been organising my programs that way.

For the longest time Java had been very keen to be explicit, to the point of needing a log of cruft where it just felt like the compiler was checking you spelt every letter of the incantation correctly because both the compiler and you knew unambiguously what simple thing you were trying to achieve. But this tone changed in Java around the time of lambdas saving you typing out classes and anonymous classes and Java became a much nicer experience imo.

Nursie · 23m ago
Now if we could just wean some more of the ecosystem away from the framework fetishism... there's no reason java programs have to be so huge, unwieldy and slow to start.

No reason apart from the framework epidemic that's supposed to make things easier for developers, but in the end hamstring them and weigh everything down.

voidfunc · 31m ago
Meanwhile some languages like Python still suck 30 years later.
vincnetas · 32m ago
Most likely you have not seen horrible languages or your bar for being not horrible is quite high.
mrkeen · 7m ago
Or they've seen enough good languages to push Java down.
adgjlsfhk1 · 1m ago
this one. Java is far from the worst out there. I've used MuMPS and know of the horrors of TCL, but Java is once of those languages where everything takes 5x more more code than it should, and the result always feels ugly.

part of my dislike is probably that I'm a math person, and the lack of operator overloading really makes any math not using the built-in types dreadful to read.

guidedlight · 17m ago
Even so. It has amazing backwards compatibility and package management.
yohannesk · 43m ago
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?
BinaryRage · 34m ago
See Brian's article "Paving the on-ramp": https://openjdk.org/projects/amber/design-notes/on-ramp
mhh__ · 36m ago
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)
textlapse · 25m ago
A special static class that cannot be instantiated is not OOP already.

C# does this well by letting you OOPfy your other code but doesn’t require you to use OOP for this monstrosity.

The_Fox · 3m ago
I distinctly recall early in my first university programming courses the instructor saying something to the effect of "Just wait until you learn 'public static void main'". I think we had only used BlueJ until that point in the course.
winrid · 16m ago
Did it slow down compile times at all to support two different file structures?
DeathArrow · 4m ago
What I would like to see deprecated is over using objects and design patterns and SOLID and Uncle Bob principles, so we see less FizzBuzz Enterprise Edition and Java feels less as the Kingdom of Nouns.
_b0t · 9m ago
Not understanding why having a well-defined function declaration "sucked", but alright, I guess!

I mean even this part:

``` var name = IO.readln("What is your name? "); IO.println("Hello, " + name); ```

is _worse_. `IO.readln` doesn't tell you whether that's file I/O or stdin/out. The more explicit the better, if you ask me.

another_twist · 36m ago
This is not a prank right ? Is it really gone ?
bonzini · 18m ago
It is, and it will be back soon just like Python's "if __name__ == '__main__'"...
garbagepatch · 3m ago
It makes sense to still have a main function. It doesn't make sense to have a class only to wrap that main function.
furyofantares · 43m ago
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.
DeathArrow · 8m ago
C# has top level statements since 4 years ago. Not only you don't need a class, but you don't even need a Main() method.
Panzerschrek · 41m ago
So, Java now supports free functions (not associated with some class). Or not really yet?
happymellon · 16m ago
They are associated with a class, but the class is basically the file. There are limitations by doing it this way but it is out of preview and officially supported as of Java 25.

https://openjdk.org/jeps/512

BinaryRage · 32m ago
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
naruhodo · 16m ago
Nope. It's just sugar. [1]

It's somewhat implicit in the JVM spec, but functions are always bound to classes as methods. [2] The only kinds of heap objects you can have a reference to are class instances and arrays. [3]

The lack of free functions is really only a minor inconvenience for language implementers. Clojure, for instance, just compiles new classes to hold functions as methods.

From a programmer's perspective, you can write lambdas, but again, it's just syntactic sugar over an inner class.

[1] https://www.happycoders.eu/java/main-method/ [2] https://docs.oracle.com/javase/specs/jvms/se23/html/jvms-4.h... [3] https://docs.oracle.com/javase/specs/jvms/se23/html/jvms-2.h...

ninjin · 29m ago
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...

vincnetas · 33m ago
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 · 32m ago
> What for would you use true free functions?

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

rerdavies · 28m ago
Cluttering up global namespaces? ;-P
TZubiri · 31m ago
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.

throwmeaway222 · 33m ago
Might come back to Java
cynicalsecurity · 32m ago
Why did it suck exactly?
riffraff · 1m ago
[delayed]
olalonde · 14m ago
Excessive boilerplate code.
hdjrudni · 19m ago
That's what I wanted to know too, but all we get is this one line:

> 1: When I was a Freshman in High School I asked a Junior what it meant. He had no clue.

OK... so it's confusing for juniors. A lot of stuff is. I probably didn't know what it all meant when I started either, but so what? You copy and paste it and move on. Eventually it makes sense. Not a big deal.

_moof · 13m ago
I don't understand how anyone ever didn't know what this meant. You have a class. It has a static method. The runtime starts your program by calling the method, passing it an array of command-line arguments. What's mysterious about this?
hmry · 3m ago
The fact that you have to explain what classes are, and what static methods are, a huge load of information, for a hello world program. And what's worse, it will leave students rightly confused about what the point of the class is, if it only has static members... Making it more likely they don't retain any of the information. Or alternatively, just say "type it exactly like this, don't think about what the magic words mean" which is a great way to ruin programming for people
maxlybbert · 5m ago
The first book I read on Java managed to explain "public static void main(String[] args)" by the end of the first chapter. It wasn't a long chapter, either.

I don't like Java, and the excessive boilerplate is a big part of that opinion. But it was never nearly as arcane as some people here are making it.

GaggiX · 34s ago
Why there is a class in the first place
TZubiri · 32m ago
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.

yallpendantools · 49s ago
> 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.

I think this is the exact audience for this change: for newbies in day 1 of 10 years in their programming journey. Less boilerplate to just swallow, less time spent debugging an otherwise-fine lab exercise if not for the wrong instantiation of Scanner, more time actually focusing on the basics they should be focusing on.

Granted, I still think Java is a horrible first language to learn from or teach with but this is a step in the right direction. Might revisit this opinion in a few years, who knows.

Oh also, we use Java in production so we also have a bunch of ad-hoc "scripts" written in Java for mostly one-off interactions. Nonetheless, these scripts can get unwieldy fast. You'd think I'm exaggerating the benefit here but I, for one, welcome one less level of indentation in these scripts.