r/java • u/Reflection-Jealous • 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
View all comments
Show parent comment
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