r/AskProgramming • u/Zd_27 • Mar 20 '25
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?
226
Upvotes
1
u/emlun Mar 21 '25
I've spent most of my professional career with Java. It's fine. There are younger languages I like less. But here are a few specific things that annoy me in Java compared to languages like Scala, TypeScript and Rust:
No block expressions. In Scala, Rust and many others,
{}blocks are expressions and can return a value - so they also don't have the ternary conditional operator? :, becauseif-elseandswitchblocks are also themselves expressions. This simple thing is more significant than you might think, because it leads to a style I call "expression-oriented programming" which I find pleasant and readable, and it also gets much more use out of the type system. The reason for that is that statements all have the typevoidor ("unit" or()or whatever the language calls it), so a program still type checks if you add or delete a statement that runs side-effects like a setter. Expressions on the other hand are type checked, so if your program is oriented around transformations of data rather than side effects, you can "program with types" to increase the chance that if some future change breaks the logic it will also break the types and thus be caught at compile time.finalis unintuitive. It means reference immutability, not value immutability. An array in Java is always mutable, even whenfinal. Only primitive values are made immutable byfinal, so it's not really that useful. It's impossible in Java to write function signatures that guarantee through their types that they will not modify their arguments, unless that is guaranteed internally by the parameter type. So you have to read the documentation of both the function and the parameter types to know what to expect. Afinalfield is not immutable if a getter returns it by reference, unless its type is internally immutable, so it's a lot of work to design APIs that enforce their own invariants.Functional interfaces are incompatible with checked exceptions. This means if you a lambda function whose body might throw
IOExceptionfor example, well tough luck, you can't pass that as aFunction<T, R>argument because that interface doesn'tthrows IOException. You have to either work around to not throw (not always possible), wrap it withRuntimeException(breaks upstreamcatch IOException) or change the target parameter to a functional interface thatthrows IOException(not possible if it's not your function, and now all other call sites have to handleIOException). It's just really clunky to work with.I'm sure I could think of more, but those are some big ones. And you might notice they're not that big really, it's annoying but no big deal. Project Lombok gets rid of a lot of the boilerplate people tend to complain about, and I also think "everything must have getters/setters and everything is done by mutation" is poor design in the first place (see the tirade on expressions above). There are many languages I like better than Java - and many I like less - but modern Java is fine.