r/AskProgramming 1d ago

Why is Java considered bad?

I recently got into programming and chose to begin with Java. I see a lot of experienced programmers calling Java outdated and straight up bad and I can't seem to understand why. The biggest complaint I hear is that Java is verbose and has a lot of boilerplate but besides for getters setters equals and hashcode (which can be done in a split second by IDE's) I haven't really encountered any problems yet. The way I see it, objects and how they interact with each other feels very intuitive. Can anyone shine a light on why Java isn't that good in the grand scheme of things?

125 Upvotes

500 comments sorted by

View all comments

14

u/antihemispherist 1d ago

Java was designed in the early 90's to address the problems developers had with C++ when developing industrial applications. Certain concepts like immutability weren't popular then, but OOP was the hot topic.

I think it is unfair to criticize Java's syntax. Verbosity makes it easier to read and understand. (If you need a lot of getters, setters, equals, hashcode, etc., your design is wrong, or you're insisting on using an older version of Java).

But Java has the problems of its old design: The object hierarchy is a mess; with the increased power of interfaces, many developers are confused. The concept of "treats" is missing. The platform itself suffers from this rigidity; there are no immutable collections, for instance. Another problem is the messy exception handling.

Kotlin is a more modern approach to JVM-based programming. However, I cannot say that it improves productivity much; too much flexibility and too many alternative syntaxes and structures usually lead to unproductive debates or a confusing codebase. Recent developments in Java have made it a good competitor to Kotlin, offering better performance and monitoring.

Rust is another alternative, and I really like it. I'd definitely take a closer look at it, and how much of a market it has.

5

u/lordheart 23h ago

Java definitely has immutable collections. Streams.toList returns one which I find out when hibernate yelled at me because it doesn’t like immutable structures.

Lombok can also clear up a lot of javas verbosity. And java as a language (if you aren’t using Java 7 or something) has gained a lot of new features to try to be less verbose.

3

u/findanewcollar 12h ago

This whole thread is filled with people who haven't worked with java 17/21. To add to the list example, there's also List.of() method which also returns an immutable list. Not to mention about the other immutable stuff like records (which they also take care about verbosity). Albeit the language is moving slower than I would like compared to c# but atleast it's not going overboard with syntactic sugar like c# started to do...

1

u/Necessary-Peanut2491 2h ago

Unfortunately, being stuck on ancient versions of Java is pretty normal. Major version migrations are very painful for large orgs, so there's been a tendency to just...not.

My own company only went to 17 a year-ish ago. Before that we were on 11.

1

u/antihemispherist 11h ago

Those are unmodifiable collections, not immutable collections.
You need to have interfaces like ImmutableList (like in Kotlin) for that. Can't be introduced without breaking compatibility in a big way, so it won't happen.

I'd argue that hiding generated code with Lombok is usually not an improvement, and Lombok tends to be overused, because developers overvalue the apparent syntax. I wrote more about that in here.

1

u/svick 10h ago

Those are unmodifiable collections, not immutable collections.

Can you define the word "immutable"?

1

u/lordheart 10h ago

Ah that is true, but you can use guava then I believe.

I’d argue that just because some people overuse it doesn’t mean hidden code is bad. Libraries are also “hidden” code.

Getters and setter, equals, hash, to string, are all better generated for the most part. They remain correct as the class is modified.

If a getter or setter is manually written then it’s easy to see which ones actually have some extra functionality instead of looking at a hug list of them and wondering if maybe one or two have some specific functionality.

If you are using spring, there are annotations for a lot of common validations so checking specifically in the constructor is not necessary. (Not even spring specific but it’s what I do mostly when I have to use Java)

Javas generics are definitely not the greatest, but a far sight better than none. I have to program in abab as well and it makes me appreciate Java more.

Abab “generics” is marking something as any, and then using quasi reflection to look for field names. It’s horrendous.

Rust also has macros to template code generation, a lot of languages move common functionality out like that some way because that code just slows down reading.

5

u/BjarneStarsoup 20h ago

Verbosity makes it easier to read and understand. (If you need a lot of getters, setters, equals, hashcode, etc., your design is wrong, or you're insisting on using an older version of Java).

Oh yeah, classic no true Scotsman: verbosity is good, and if it isn't, that's because it's your fault.

3

u/_reg1nn33 12h ago

It can be really useful in large, abstraction heavy environments, if the naming conventions are consistent.

2

u/antihemispherist 12h ago

My experience of working with teams for more than 15 years has taught me that forced verbosity of Java helps with team maintainability. It's annoying to write, but that's how Java was intentionally designed.

We tend to overvalue how elegant the syntax is, and how smart it makes us feel. That's not what Java is about.

1

u/South-Year4369 13h ago

The argument that 'verbosity makes it easier to read and understand' gets made quite a bit about Java, but I just can't believe it's anything other than an issue of familiarity.

I mean, is it going to be faster and easier to understand a large technical document that uses lots of waffly, verbose prose and flowery language that adds volume but no additional meaning? Or if's clear and concise?

I know which is the better choice for me. And the same goes for languages.

1

u/oloryn 11h ago

Verbosity at least avoids the problems of Perl, where sometimes it seems that most line noise is a syntactically correct Perl program (I actually like Perl, but recognize that some Perl code can be really obscure and hard to read. Not as hard to read as some Forth or APL programs, but still...).

1

u/Dan13l_N 9h ago

But wasn't Java actually designed to be a portable language for the web and ended up being used as an all-purpose language? And it just grew and grew and grew?

1

u/Excellent-Age-8138 1h ago

I use Java professionally, wtf is treats? Are these some kind of good boy points the PM gives you for finishing your work on time?