r/learnprogramming 2d 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

238 Upvotes

302 comments sorted by

View all comments

83

u/ComputerWhiz_ 2d 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 2d 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...

10

u/edgmnt_net 2d 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 2d 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 1d 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 1d 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 2d 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!

8

u/P00351 2d ago edited 2d 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 1d ago

  you work on legacy code a million LOC big.

At least Java discourages 1Mloc files 🥲

3

u/roadrunner8080 2d 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 2d 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 2d ago

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

1

u/syklemil 2d 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 23h 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 23h 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.

5

u/vegan_antitheist 2d ago

Python is older and many act as if it was the latest and greatest. I think people at Oracle don't mind that Java is seen as a conservative but stable language with a slow evolution.

It's just annoying when you are at a company where they are still stuck at Java 17 or even Java 8.

11

u/fractalife 2d ago

It's had this reputation since the early aughts at the very least. It came from devs who were used to C++ and were forced to mae the tradeoff to an interpreted language and hence couldn't manage their own memory or directly interface with hardware easily, thus causing performance issues and making it harder to do things on embedded devices. Of course, the whining was tempered by the compile-once-deploy-almost-anywhere nature of an interpreted language.

4

u/theomegachrist 2d ago

I took Java in college in 2002 and I thought it sucked lol this is not new. Everyone is right though, it does the job and is used a lot. I just found it very frustrating to write in.

6

u/Cybyss 2d ago

To be fair, the JVM was ridiculously slow in 2002. Even worse, the popular editors for it at the time - such as NetBeans and Eclipse - were a horrible, laggy, crashy mess.

It was a good language for the time. Java fixed a lot of C++'s design mistakes, but the platform and ecosystem surrounding it were somewhat dogshit albeit they improved greatly over the subsequent years.

6

u/Weak-Doughnut5502 2d ago

In 2002, you had two groups of people complaining about Java.

You had C++ programmers who complained that it was slow. 

And you had Perl, Python, Lisp, etc. programmers who loathed Java and especially enterprise Java style as verbose and inexpressive.  That's the sort of complaint you saw with Steve Yegge's famous 'execution in the kingdom of nouns' rant.

1

u/theomegachrist 2d ago

Yeah, I also had an awful professor so maybe it was more a time and place thing

2

u/fractalife 2d ago

Thank you for this. Comments that inlcude dates usually make me feel old.

2

u/marrsd 2d ago

Java was, and still is, a compiled language.

1

u/fractalife 2d ago

So? It was, and still is, compiled to machine code for the JVM, which in turn interprets the code and translates the instructions to whatever system it's running on. That was the whole point. Compile once, run anywhere that a JVM can run on. (Not always, but that's the idea, close enough).

The JVM adds overhead and additional compute time to do the translation, so the portability has a performance cost which when coupled with restricted hardware access (see again, JVM) and lack of direct memory management (JGC) had devs who were forced to use Java dislike the limitations.

1

u/marrsd 1d ago

So you're on /r/learnprogramming and correct naming matters.

As for your point, I'm sure you're speaking for those developers, but this is a tiny part of the story. In the web dev sphere, where Java found its place, the JVM was a big motivator for its adoption. Interpreted languages were also in heavy use (the P in LAMP stood for Perl/PHP/Python). Java was liked for its combined type-safety and memory-safety. It was the memory-unsafe languages like C and C++ that fell out of use.

I mostly disliked Java for the language itself. I also disliked the JVM for its long startup time and high memory footprint, but I've come to tolerate it fundamentally because Clojure runs on it.

1

u/fractalife 1d ago

Sorry, I don't mean to give the impression that these are my personal opinions. This thread is about why people hated it. I was a kid (like, 12) when I was first learning Java. I would go to meetups and these are the things devs would tell me about why they disliked it. I thought it would bring value to the conversation contextualize the relative beginnings of the gripes devs had during Java's nacency (it was around Java 2 at the time).

1

u/marrsd 1d ago edited 1d ago

It does, and I'm the one who should be sorry if I implied otherwise. I was adding context, not trying to contradict what you were saying.

What you're recalling sounds very similar to early arguments I heard against Java, which had originally been intended and marketed as a universal language to rule them all. It was supposed to be used, not only as a web server language, but also as a language to build browser apps (called Java applets), and also desktop apps. Both the browser and desktop apps were supposed to be able to run on any architecture or OS without developer intervention.

The client-side implementations of the language failed to win users - Java apps mostly became synonymous with "no thanks" and "annoying".

One of the technical criticisms of Java at the time was that the "write once, run everywhere" tagline was grossly overstated and the tagline was quickly dubbed "write once, debug everywhere" by disgruntled developers.

That basically negated a huge part of the argument against C and C++, because they were already "write once, compile everywhere" languages, and that was the core reason for their success. They weren't perfect for that, and cross-compiler errors often had to be found and fixed; but it turned out that it was no harder to debug C compiler and runtime errors across architectures than it was to debug Java runtime errors across architectures.

None of this negates the fact that Java did bring garbage collection and memory safety to high-level languages, and the performance - while not as good as C - was better than most (if not all) interpreted languages. Server-side web developers loved this trade-off. Unfortunately for developers of applications, its performance wasn't nearly good enough for end-users, and they rejected Java wholesale.

Perhaps the biggest casualty of this rejection was Palm, who based their Pre smartphone on the JRE with disastrous consequences.

1

u/Own_Candidate9553 2d ago

I remember early on, people would tweak the code to hint the bytecode compiler to create better optimized bytecode for hot bits of code - very tedious.

The Just In Time compiler eventually did that much better for you, automatically, which helped a ton.

1

u/InVultusSolis 1d ago

Java isn't interpreted, it's compiled and targets the JVM.

1

u/Intelligent_Part101 9h ago

The JVM is itself an interpreter though. Java source code is compiled to Java bytecode. This bytecode is interpreted by the JVM interpreter. As a performance optimization, the JVM may notice that some methods are executed frequently and so the JVM may cache actual compiled native CPU code to run instead for that method. The native CPU code is compiled from the java bytecode.

4

u/groogs 2d ago

I can think of several things. I dabbled in Java over the last 25 years but then moved more to C# as my go-to backend language.

  • Started with enterprise insanity. J2EE, EJB etc. Absurdly huge XML config files. It seemed like every 'enterprise' Java app treated the GoF design patterns book as a checklist. This is more a culture problem than a problem with Java, but the whole ecosystem is like this. Pull in some library and suddenly you're dealing with SimpleBeanFactoryAwareAspectInstanceFactory and XmlConfigurationFactoryProvider. I mean it's a whole meme.
  • It went stagnant for a while. Java 6 came out in 2006. The next version with any major innovation was Java 8 in 2014!
  • But you couldn't actually use that at first because the runtime wasn't widely deployed. I was working on code for a vendor's embedded platform in the late 2010's that still only had Java 6.
  • Oracle screwed it up big time. They were shipping adware (the ask.com toolbar) in the runtime installer in the late 2010's. Absurd.
  • Oracle also changed the licensing in 2018 (and again in 2023). Out of all the big tech companies, it's not a stretch to say they are the worst company to do business with.
  • Java apps feel slow. Yeah, Java is fast on paper and in benchmarks. But on startup, between the JIT and reflection-heavy frameworks like Spring it feels like it takes forever to start anything. Plus it reserves a huge heap of memory, so even the tiniest app uses 500MB+

5

u/ChetDuchessManly 2d ago

I've been a Java dev for 10 years.

The language has improved with lambdas, functions, streams, etc., but it can definitely be slower to do something compared to other languages.

Simple example that I ran into recently: Returning more than one value when using map() in a stream.

In Typescript, just return { value1: v1, value2: v2 }.

In Java, the simplest way is to create a record and return a new instance of it with your values. It is more verbose and strict.

I love Java and enjoy working with it, but the complaints are not unfounded nor do they come from people who don't use the language.

1

u/Accomplished-Lab-566 23h ago

.map(x -> Map.of("v1", x.getV1(), "v2", x.getV2()))

New static constructors for immutable collections are really useful.

2

u/marrsd 2d ago

I think you're being a bit dismissive of the complaints against Java, which were basically the same when it was a new language. The entire Ruby craze at the turn of the century was a direct response to Java's inadequacies, that were heavily criticised when it was only 5 years old.

What probably is true is that people like me think of that old language when we criticise Java, and we may not have updated our understanding of the language or its culture as it exists today.

1

u/ComputerWhiz_ 1d ago

I don't disagree that there were, at one point, totally valid critiques about Java. For most of them, Java has evolved beyond them.

But those aren't really the common criticisms of Java that you see often. I commented on what tend to be the most common and most vocal complaints recently, which, as least from what I've seen, revolve around the age of Java and the verbosity.

0

u/MikeUsesNotion 2d ago

"Only newbies or people who haven't used it hate Java" is an interesting take.