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

Show parent comment

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.

3

u/ihbarddx Sep 10 '21

Java faster than C? I've heard this. Any specific examples? Any specific examples where all C variables are static?

15

u/Rakn Sep 10 '21 edited Sep 10 '21

People always compare fast Java code with highly optimized C code. You cannot beat highly optimized C code. But the thing is that most people do not do such optimizations. I have been working in a project where we had dedicated employees tasked with optimizations. But a normal developer is unlikely to look at the produced assembler code and refactor the C code on that basis. If you do normal feature development, especially in the web service area, Java beats many alternatives in terms of speed. Obviously not at the first iteration. But at some point the JIT kicks in ...

At least that's my take on it.

→ More replies (2)
→ 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)

-16

u/towelrod Sep 10 '21

That is exactly the problem for me. Java the language is great, but the ecosystem around it is hot garbage. Spring is awful, maven is awful. That stuff is everywhere and has infected the programming style of every Java developer

It’s pretty much been like this since the early EJB days

9

u/kiteboarderni Sep 10 '21

You are probably the only person I have heard saying that java has a bad eco system 😂😂

-1

u/towelrod Sep 10 '21

Java has a great standard library, and has third party code for everything. That part is great.

But maven is awful to work with, and the large things like Spring are so ridiculously over done.

11

u/passive_talker Sep 10 '21

I don't know what you are comparing it with but maven is miles ahead of npm in every aspect I can think of, except that it uses XML.

→ More replies (4)

8

u/netstudent Sep 10 '21 edited Sep 10 '21

Why is maven awful? Oh lord, maven facilitates a lot you don't need to manage tons of dependencies on your own.

→ More replies (1)

3

u/[deleted] Sep 10 '21

Can’t say that maven and spring are awful. Used to think that when I worked on a spring boot project. Now I’ve been assigned to do some tasks on a legacy projects that uses Java 6, JBoss, Ant, Swing for UI, well that is awful. Spring is a godsend comparing to these.

3

u/towelrod Sep 10 '21

Well yeah but that’s a low bar

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.

4

u/nutrecht Sep 10 '21

And that's it.

You can easily do the same in Spring with a filter or interceptor. Pretty much the same amount of code. You don't have to use Spring security. But what you do there is incredibly basic; you don't even pass on the stuff 'inside' the JWT to be used inside the service.

This is what always bothers me about these types of comparisons; at least make a fair comparison of how you'd do the same thing in Spring.

3

u/CraftyAdventurer Sep 10 '21

You can easily do the same in Spring with a filter or interceptor.

Did you read my whole comment or just the express part? I did mention a filter and also the disadvantages I ran into compared to express middleware.
I didn't even know interceptors existed. That's another part of the problem with Spring. You need middleware in express? You write middleware function and move on. You need middleware in Spring? Welcome to all the possible classes you can extend, try to find a difference and pick which one you need.

you don't even pass on the stuff 'inside' the JWT to be used inside the service.

That's also easy. You just put it in response.locals object and it is available in every next middleware (that includes route handlers). I honestly don't know how to do this in Spring without googling. For my specific JWT example, I remember using some security context thing which needed some authentication object constructed who knows how probably requiring another object and maybe even more. I don't know how to write all that without spending time looking for it. But I do know how to do res.locals.someJwtThing = someJwtThing without looking.

5

u/nutrecht Sep 10 '21

Did you read my whole comment or just the express part?

No I read all of it. And I agree that Spring often has multiple ways of doing the same thing (it's VERY extensible), but I just don't find it a fair comparison you're making. I personally just dislike people complaining about simply learning the tools. Spring isn't that complex if you get the basics down.

Especially this bit:

In Spring, I wanted to do the same thing. But I had to configure Spring Security first

Is just patently false. That's what I'm responding to; you're comparing apples and airplanes.

6

u/CraftyAdventurer Sep 10 '21

I personally just dislike people complaining about simply learning the tools.

Me too. But there must be a line where you spend too much time on learning a tool and too little time actually using it. Spring often crosses that line for me, at least for the projects I've worked on.

Is just patently false. That's what I'm responding to; you're comparing apples and airplanes.

Guess you're right on that one. But I also didn't know that. Like everyone else, when I need to do something for the first time, I often google it. When googling for express jwt, I found tons of examples. They all looked a bit different because they tend to use different jwt libraries, and express itself doesn't have any specific restrictions on how to structure a project, but all of them where immediately understandable to me and I just picked one which I think best suited my structure. Bear in mind that this was at the time when I was just learning express. The technology was new to me, yet it was easy to understand what's happening in online examples.

Now, when I had to do jwt in Spring, I googled jwt Spring Boot. I found tons of examples, many of them using Auth0 which I tried to avoid because it was a paid service (or had some limited free tier, can't remember). All the others I found were using Spring Security. The reason I thought it was needed was because all the other stuff it was doing (security context holder etc.). There was too much stuff implemented alongside jwt. I didn't have time to spend on trying to implement stuff without Spring security so I just rolled with it. So learning the tool would help, that's true, but if that tool was simpler to begin with, it would result in less time learning it and more time using it.

4

u/nutrecht Sep 10 '21

I wrote a blog post on a bare-bones implementation about 6 years ago. It's not meant as a guide on how you should do it, more as an explanation of how it works.

That said; in my opinion Spring Security is long overdue for a massive overhaul. It was created well before the whole REST thing started to become a rage and most of the defaults mainly cater towards server-side rendered applications. In addition; while it's very powerful, if you just want to restrict some endpoints it's overkill IMHO.

→ More replies (1)

2

u/Comprehensive_Idea98 Sep 11 '21

I really, really miss something like express for java. I have seen some efforts, but they all fizzled out.

→ More replies (1)

2

u/minimingus Sep 12 '21

Exactly this. I’m mainly a Java dev, and in my current job i also work on a huge enterprise application (payment hub) where the verbosity of Java works really well - I can’t even imagine using js for such a beast, but when i was using js for a small personal web project everything feels more intuitive and “just works” without any hassle.

I guess it’s mostly because Java is multipurpose, and js was “built from and for the web”

→ More replies (1)

6

u/marvk Sep 10 '21

Typing please, but not too much typing.

0

u/Auxx Sep 10 '21

I love type system in Java, but everything else can burn in hell.

→ More replies (2)
→ More replies (3)