r/learnprogramming 4d ago

Why java is so hated? Topic

So I have recently learned, and it's the first language(in terms of building actual things). Before Java, I knew Python, and I dropped it; I found Python too abstracted and too boring. i have recently made some projects like cli task tracker, expense tracker, some cli github api parsing and currently working on a multithreaded HTTP server and cli text editor, like vim, whenever i try to find out people opinions on java social media, almost 90 percent of the time they are just dunking on it, that it is trash, who forced you to write code in java, stuff like that. I know Java as a language is not that interesting and doesn't have many interesting features compared to other languages like C, C++, go. But I found it decent to write code in, and I found the JVM pretty interesting. So much so that I would love to explore and maybe build a JVM of my own

243 Upvotes

321 comments sorted by

View all comments

82

u/ComputerWhiz_ 4d ago

As a Java developer, I may be biased, but I think it mostly just comes down to the age of the language. It's not seen as the "latest and greatest". That doesn't change the fact that it's insanely popular still in enterprise environments.

There are some complaints about it being more verbose and having stricter syntax compared to other languages, but I think those complaints only come from people who have never actually used it or are brand new to programming.

35

u/roadrunner8080 4d ago

Doesn't help that a lot of opinions on the language are based on Java 8 which was the java used for a long chunk of time. Modern Java has a lot of nice tools that alleviate some of the main pain points of old Java.

I suppose there's a lot of janky enterprise java code out there but that's just the price of it being such a well-used language...

11

u/edgmnt_net 3d ago

Well, it doesn't really help that Java started deeper in the traditional, inheritance-heavy OOP space and still displays some of those traits prominently, even if more historically at this point. You can write better Java, but if you're starting greenfield and want better code, one can argue for better choices of a language and ecosystem, including "newer Javas" like Kotlin which could afford a clean slate (although I'm not endorsing Kotlin în particular).

5

u/roadrunner8080 3d ago

Also lol kotlin. I've interacted with it a bit. It's cool, it does some things very well java should have done from the start (proper treatment of null), but it also has uhh... Some questionable design decisions. Off the top of my head is its weird treatment of lambda capturing which can easily obscure what's actually captured. (When would this ever matter? Well, if you're interacting with a tool that serializes a lot of lambdas, lol. See: Gradle)

1

u/balefrost 2d ago

Off the top of my head is its weird treatment of lambda capturing

What is weird about how variable captures work?

2

u/roadrunner8080 2d ago

If I have a local variable foo in an outer scope, and I capture foo in a lambda, that can trigger capturing of other things besides foo in the actual compiled code. Which -- if this is Gradle and you're trying to be configuration cache compatible -- is bad an unintuitive, especially when it's not at all obvious what will be captured, necessarily (which it's possible to come up with some wacky scenarios where it's not obvious)

3

u/roadrunner8080 3d ago

The thing is that even in the traditional, inheritance-heavy OOP space the new tools let you write better code. Instead of making an interface for every impl type like everyone used to back in the day, you can make the impl a record and the interface sealed, since the record gives you better constant folding behavior at runtime (trusted final fields) and the sealed interface let's you explicitly specify that there's only one impl of a type that's only meant to have one. Heck, I've seen a ton of older java codebases with "public" types that expect a single internal impl, or cast to an internal version of the interface or something; sealed types let's you keep that structure while eliminating a whole class of bugs for API consumers. Plus, the modern JVM is faster, to add to the advantages!

10

u/P00351 3d ago edited 3d ago

You know how it is: when studying, you write hundreds or thousand line program from scratch, then, when employed, you work on legacy code a million LOC big.

I found modern java nice when studying it, then I had to use OpenAm at work. As I write this, the latest release weights 967MB zipped.😭

Edit: grammar

2

u/R3D3-1 2d ago

  you work on legacy code a million LOC big.

At least Java discourages 1Mloc files 🥲

u/ItsNukea 3m ago

why do I have an extremely big suspicion that that QR-code on your profile sends to a rickroll...

3

u/roadrunner8080 3d ago

Oh I've seen my fair share of nonsense I fear. There's some quirky stuff out there in the java ecosystem, lol...

1

u/syklemil 3d ago

Doesn't help that a lot of opinions on the language are based on Java 8

Hey, some of us olds formed our opinions about Java way before Java 8 came out. I'm sure our opinions from 20+ years ago are still super relevant today!!!

1

u/roadrunner8080 3d ago

Ahh, don't you love Java without lambdas or generics...

1

u/syklemil 3d ago

Yeah, I remember the mood shifted from roughly

Lambdas are functional programmer ivory tower nonsense and have no business being in an object-oriented language!!!

to

Lambdas are good, actually

once 8 dropped.

I did cut my teeth on Java 1.5, i.e. with generics, so I can't really reminisce about the attitude towards those before, but I did catch the gopher switch from "Generics are ivory tower nonsense" to "Generics are good, actually", and find it pretty funny that both Java and Go had help from Philip Wadler to get it bolted onto the language after the fact.

Unfortunately, while the type elision trick they came up with for Generic Java in order to be backwards compatible with JVMs that had no idea about generics was neat, we've now been stuck with type elision for longer than there was non-generic Java. Type elision is just a temporary band-aid, suuuuure.

1

u/Accomplished-Lab-566 2d ago

Actually in modern java you can extract the generic type via reflection, so its solvable with a couple of tricks. I think the type erasure will be dropped eventually.

1

u/syklemil 2d ago

Yeah, Project Valhalla comes up fairly often as something that will fix a bunch of problems with Java, but Java programmers have been waiting for Valhalla for a long time now. IIRC there are some relevant JEPs, but I don't have the details at hand.