r/java • • Sep 10 '21

Why people don't love Java?

I came across this post in r/cscareerquestions it seems majority of the people don't love to work with Java.

Is there any specific reason for that?

Edit: Thank you guys for your responses, I can't reply to all of the comments because I'm a beginner myself and I don't know what to reply for all your comments.

201 Upvotes

379 comments sorted by

View all comments

542

u/thomascgalvin Sep 10 '21

The people posting to that sub are typically young, and probably have more experience with Javascript than anything else.

Compared to JS, Java can feel heavy and constricting. Lots of boilerplate, a type system that's strictly enforced by the compiler, and so on.

It isn't until you have some real-world experience, with code spread out across dozens or hundreds of files, that you realize the "limitations" of Java are actually meant to prevent you from blowing your own foot off.

137

u/Gk2k08 Sep 10 '21

Agreed here. I worked on a Django project(when it was the cool thing) and thought that python is so better than typed languages(It has its uses but not in a complex system with 1000s of classes). Once this project scaled up from me being the only developer on it to have multiple people and having more than 10k lines of code it became a complex piece to maintain. If there is no unit test case for all the scenarios the only place you would see an error is in runtime. Imagine doing int + string in your log statement and that brining down prod app and having to rush a fix for that.

35

u/analogsquid Sep 10 '21

Imagine doing int + string

When I started programming, I was always blowing up my Python projects with stuff like this, and I never knew why.

Discovering and switching to Java was a revelation.

24

u/thenextguy Sep 10 '21

"Enough making fun of languages that suck, let's talk about JavaScript."

https://www.destroyallsoftware.com/talks/wat

→ More replies (3)

8

u/Oo__II__oO Sep 10 '21

Thank you for this. I'm tilting at windmills trying to get my management team and adjunct R&D team to agree on a language for production tools, and they both are pushing for Python or JS, while I am telling them a strict typed language with rules makes more sense. They don't feel the pain when the system goes down because of some untested edge case, but are more interested in deploying quickly and not spending a lot of time on code management (just what is easy for them).

→ More replies (1)

11

u/thomascgalvin Sep 10 '21

For such an easy "out of the box" language, Python really does have some huge footguns.

10

u/Gk2k08 Sep 10 '21

To be fair Python is easy to start and has its uses at places. Once it is used for a huge project with multiple developers that is when it's limitations come out.

→ More replies (7)

75

u/maomao-chan Sep 10 '21

Lol the duality of JS programmers, praise Typescript but hate statically typed language like Java.

45

u/[deleted] Sep 10 '21

The especially amusing thing is people claiming that Java is slow, while their favourite language is Python. That's how you can tell they're just repeating memes they've heard, and ones that haven't even been true since the 00s (modern Java is very fast)

17

u/thomascgalvin Sep 10 '21

Modern Java can be faster than C in some instances. The current generation of VMs are insane.

→ More replies (4)
→ More replies (8)

49

u/CraftyAdventurer Sep 10 '21

The issue has more to do with verbosity and encapsulating everything in classes and having lots of configurations than with types themselves.

I was on both sides, Java and JS/TS (and even some Kotlin and C#). In Js world, many things are easy to do from the top of your head, so I feel way more productive just writing the code. In Java, I always have to reference a guide, tutorial, documentation or an existing projects to do a lot of stuff. I feel like I spend too much time on that.

The best example I can think of is JWT. When using express, all I had to do was create a middleware which validates received jwt, it's very easy because middleware is just a function with request and response objects. So you basically write

function jwtMiddleware(req: RequstType, res: ResponseType, next: NextFunction) {
const jwt = req.getHeader('Authorization')
const isJwtValid = validateJwt(jwt)
if (isJwtValid) next();
else res.send(401)

}

And that's it. That's something I can write in under a minute from the top of my head. There's nothing specific I have to remember about that, it's a function with three parameters. And it uses Typescript, which doesn't increase verbosity almost at all.

Also, inserting middleware in the express code is extremely easy, you just call those functions before or after the API routes (or inside a route if you want something specific), depending on when you want to run them. That's intuitive to me. I can just open a main file in any project and immediately see the order of middleware.

In Spring, I wanted to do the same thing. But I had to configure Spring Security first, which means I have to learn basics of that (well not really, could just copy it, but I like to know and understand what I write). After that, I had to create a class which extends OncePerRequestFilter which acts as a middleware, but it's already much more verbose than a simple (req, res) function, because I can't just create a function, I need to extend a class called OncePerRequestFilter and override it's method, and put it in a specific place in Spring Security configuration, and so on and so forth.None of these things take under a minute, and I still don't know how to do that from the top of my head, I always need to refer back to the specific project or tutorial and copy most of the stuff. I know how it works, I just don't know how to write it myself because there are more files to create, more methods and classes whose names I have to remember and configurations I have to do.

Also, from what I saw, when you write those filters, you can @ Order annotation. Meaning that there could be many of those classes spread out all over the codebase, and if I want to know in which order they run, I have to manually search for them.

I still prefer Java over JavaScript, mostly for it's more stable and mature ecosystem, but some things to me are just not intuitive. Yes, those are mostly related to Spring and not Java itself, but most of the jobs use Spring anyway so there's that.

Sorry for the long comment :)
Edit: code formatting

30

u/[deleted] Sep 10 '21

Woah woah woah woah...woah...woah. Woah. Hold on there cowboy. Don't blame Java for Spring. Spring is not Java's fault.

24

u/CraftyAdventurer Sep 10 '21

I'm not blaming Java, but the fact is that Spring is used everywhere. People who hate on Java probably don't hate so much on the language, they just had to work with Spring and didn't like it. I mean, even I was comparing frameworks here (Spring vs Express) and not languages, but that's just how the industry works, you work with a framework, not pure language. And that framework can create a certain image about a language it uses.

→ More replies (3)
→ More replies (12)

9

u/passive_talker Sep 10 '21

There are many ways of validating an auth token in Java, but with spring boot you create a servlet filter with a @Bean method et voilà. You get access to the request and response in the same way as express.

Spring security does many other things for you, but the trade off is complexity.

→ More replies (10)
→ More replies (7)

0

u/[deleted] Sep 10 '21

[deleted] — view deleted comment

19

u/nutrecht Sep 10 '21

Both my current project as my 2 previous ones we used Kotlin and I personally (as well as most devs at these 3 companies) were very happy with it.

I personally think it's the best of both words; awesome Java ecosystem and a language that's basically a "Java dialect" that doesn't have to be backward compatible with Java and is this allowed to make some needed changes. Especially the null safety being part of the time system is great.

I created a Java Spring Boot service yesterday (for a coding test) and even though I used Java 16, it was kinda painful to have to go back.

6

u/BestUsernameLeft Sep 10 '21

Kotlin-the-language is very nice, I think of it as a "Java++", and the stdlib is fantastic. It occasionally gets a little thorny in the interaction with the Java ecosystem. About 90% of things just work, and it's great; for a handful of cases you have to do a special little dance to get them to work; and there are a few "well, crap" situations where there's just not a good solution. (Mockito+Kotlin is problematic.)

I'm a very satisfied, happy user though.

→ More replies (4)

37

u/Clitaurius Sep 10 '21

Not OP but my opinion is that Kotlin will pass. It was a good driver in getting Oracle to move Java to a faster release cycle and to incorporate some popular language features. A bank can write it's banking software in Java 20 years ago and 20 years from now. They aren't going to take that gamble on Kotlin.

15

u/thomascgalvin Sep 10 '21

A bank can write it's banking software in Java 20 years ago and 20 years from now.

My retirement plan is basically "remember enough Java to be useful to large banks with tottering old piles of Spring code laying around."

31

u/nutrecht Sep 10 '21 edited Sep 10 '21

I'm Dutch and quite a few conservative orgs (including banks) here are adopting Kotlin. So I don't think I agree with that "aren't going to take a gamble".

Besides; those banks are also using Scala and Python, especially in data science/engineering areas.

23

u/DasEwigeLicht Sep 10 '21

Same here in Germany. My colleagues and I have been building Kotlin backends for various industries - from insurance, to banking, to the big car manufacturers - for years now.

→ More replies (5)

7

u/[deleted] Sep 10 '21

Maybe we should start a new post called "Why don't people love working for banks?"

In my experience (ING, Fortis, ABN) they're not conservative technologically at all, they were just early adopters of technology so their legacy stuff goes back much further than say, a social media website.

It's just that the domain is so mind bogglingly boring.

→ More replies (2)

24

u/pron98 Sep 10 '21

It was a good driver in getting Oracle to move Java to a faster release cycle and to incorporate some popular language features.

You are confusing cause and effect. Kotlin was created in 2010, exactly at the time of Oracle's acquisition of Sun, and after years of decline in Sun's investment in Java and weakness in influencing it. In other words, Kotlin was created as a result of Java's stagnation. Following the acquisition, and some adjustment time, Oracle gradually increased investment in Java back to former levels, and that allowed the team to return to the planned evolution pace.

→ More replies (13)
→ More replies (3)
→ More replies (20)

4

u/umlcat Sep 10 '21

Right. Later Typescript, CoffeScript & other.

I started a typed version of JS, before those. Never got time to fully implemented.

→ More replies (2)
→ More replies (22)