DEV Community

Cover image for Why you should NOT HATE Java!
Sahil Pabale for ByteSlash

Posted on

Why you should NOT HATE Java!

Everyone hates Java, even I did (once).

The memes, the videos, I mean literally everywhere there is spread one thing - java's popularity is declining...

I wondered why people hated it so much, to a point where people are even ready to buy merch out of it :P

So I decided on trying out java myself... <3

Journey of Java

So why do people hate Java?

Why do people hate Java

Java has been popular for decades. There's no such proper reason to hate Java, rather there are some things that prick many developers.

  1. Java is VERBOSE.

    Verbosity is a good as well as a not-so-good feature. Like it makes debugging much easier and reliable but at the same time, you gotta write a lot of code. Many beginner developers complain about this thing a lot - why do we just write 1 line in python and 7 lines in java just to print Hello, World! on screen? But they don't understand what both languages are meant to perform!

  2. Forced OOP

    Java is a pure Object Oriented Programming language and it was designed specifically from the very start. Even if you want to execute small programs, you have to compulsorily wrap it into classes-object form, which doesn't make sense to many beginners or devs of other languages.

  3. Memory Hog Language

    By its very design, Java is a memory hog. You simply cannot make a memory-efficient program that handles enormous data while still preserving good object-oriented abstraction in your program. This extra memory consumption doesn't matter if you are making a small-scale application. But imagine making a video editing application that has to handle gigabytes of data in real-time! That's just insane...

My journey with Java

My journey with Java

When I first encountered java, I found that language so cringes to learn. I too had that mentality of why to write long code! Instead, just use python to make life simpler. But I was wrong, I didn't even know the differences between those languages and I was simply comparing them.

Languages are simply tools that help you craft your desired application. So it doesn't matter which language you're using until you build super-efficient apps that drive you more users at end of the day :D

I learned Java and saw enormous applications of it! Like we can literally build highly scalable and enterprise-level apps using java. The Netflix you watch uses java to serve content to you ASAP.

Instead of hating java, try it out once

I'm sure you won't regret learning it once you build some cool projects with it. All you can build is an android app or a desktop app for your windows pc. Are you a web geek? try out spring boot and make scalable backend apps with it!

Just have an end goal in your mind and start your development journey! You will soon stop comparing languages and use them wisely :D

Try out java

I hope you have got some value from this article and if so, don't forget to share it with all your friends and colleagues. Because sharing is caring :P

Top comments (24)

Collapse
 
angius profile image
Angius

Question is: why use Java, if C# or Kotlin can do everything it does better and with less boilerplate?

Collapse
 
siy profile image
Sergiy Yevtushenko

Don't know about C#, but Kotlin is not an alternative to Java in enterprise setup.

Collapse
 
sahilpabale profile image
Sahil Pabale

You might be having some POV right? I would love to hear that!

Collapse
 
devdufutur profile image
Rudy NappΓ©e

Why ?

Thread Thread
 
siy profile image
Sergiy Yevtushenko
  • Kotlin requires extra efforts to keep codebase clean and organized: freedom in placing classes/functions across files tend to quickly turn codebase into blob of cold spaghetty. This is solved by defining and maintaining conventions - extra efforts mentioned above.
  • Extension methods blur class API and tend to spread across code base. As a consequence devs often repeat extension methods with very similar of identical functionality. This is also solved by defining and maintaining conventions - more extra efforts.
  • Kotlin requires keeping in mind much more implicit context while writing and reading the code - context-specific keywords, default variable names, etc. This impacts productivity in long living projects, especially when team changes.

There are more reasons, but even those listed above is enough to try to avoid Kotlin for enterprises.

Thread Thread
 
devdufutur profile image
Rudy NappΓ©e

Indeed great powers implies great responsibility... DSL and extension methods are valuable tools but should be used sparingly.

In Java because there is no extension methods and we can't define a function outside class, we must define a lot of util classes (*Util, plural classname) with their static import, I'm not sure it's better :/

IMO Kotlin offers interesting patterns to compensate some lacks in Java. But teams are free to define coding standard to avoid exotic code.

Thread Thread
 
siy profile image
Sergiy Yevtushenko • Edited

I'd rather say that all these are signs of poorly though out and inconsistent language. One laughable example is that code written with infix methods often can be made non-compilable by adding one more line feed.
Another (significant) disadvantage is that Kotlin encourages developer to write hacky, hard to read and understand code. Optional chaining and elvis operator are especially easy to abuse.

Thread Thread
 
devdufutur profile image
Rudy NappΓ©e

I'm not sure

user?.address?.streetName ?: "No street"

is weirder than

Optional.ofNullable(user).map(User::getAddress).map(Address::getStreetName).orElse("No street")

But I'm sure it's shorter :)

About infix notation, I'm not a big fan in everyday code but it can be handy for DSL. Again, great powers...

Thread Thread
 
siy profile image
Sergiy Yevtushenko

Your code is shorted for two reasons:

  • It assumes that user has type String, although for fair comparison it should have type Optional<String>
  • You just stepping through object properties (BTW, your code might be a code smell, because it knows too much about User internals). If you try to actually compose operations, your code will not look so short.

You may try to rewrite code below with optional chaining:

public UserProfileResponse userProfileRequestHandler(User.Id userId) {
    User user = userService.findById(userId);
    if (user == null) {
        return UserProfileResponse.error(USER_NOT_FOUND);
    }

    UserProfileDetails details = userProfileService.findById(userId);

    if (details == null) {
        return UserProfileResponse.of(user, UserProfileDetails.defaultDetails());
    }

    return UserProfileResponse.of(user, details);
}
Enter fullscreen mode Exit fullscreen mode

For comparison, monadic version of this code looks so:

public UserProfileResponse userProfileRequestHandler(User.Id userId) {
        return userService.findById(userId)
            .map(user -> UserProfileResponse.of(user, userProfileService.findById(userId)
                .orElseGet(UserProfileDetails::defaultDetails)))
            .orElseGet(() -> UserProfileResponse.error(USER_NOT_FOUND));
    }
Enter fullscreen mode Exit fullscreen mode
Thread Thread
 
devdufutur profile image
Rudy NappΓ©e

Just assumed User/Address were kt data classes / java POJO but Indeed callee could've been returned a Optional

Collapse
 
devdufutur profile image
Rudy NappΓ©e

Because companies are chilly ? 😁

In mine just replacing Java with Kotlin (keeping same framework, same supervision tools, same IDE...) is quite complex πŸ˜”

Collapse
 
siy profile image
Sergiy Yevtushenko

And has no sense. Kotlin "features" make keeping code clean and maintainable much harder, than with Java.

Thread Thread
 
devdufutur profile image
Rudy NappΓ©e

Lol.... Not sure if you're trolling , but in my experience it's exactly the opposite. Less code lines, using ADTs, powerful pattern matching make your code so much expressive and safer.

Thread Thread
 
siy profile image
Sergiy Yevtushenko

See my comment above.

Collapse
 
sahilpabale profile image
Sahil Pabale

yeah it's bit hard though

Collapse
 
docvominh profile image
Pham Duc Minh

Simple, MS SQL and Window Server isn't free.
.Net Core may be mature now and it available on Linux
But migrate whole company infrastructure will not easy

Collapse
 
pazvanti profile image
pazvanti

I've been a Java developer for the past 7 years. Was even a C/C++ dev for another 4 prior to that. Yes, Java is a bit "hated", but it has some really good features and it evolved a lot in the past years. I heard many arguments against Java, like "it is slow" or "it uses a lot of memory" and I don't find them all true. JIT speeds things up a lot and Java is capable or working with big quantities of data without a problem. In today's age, hardware is cheap, engineers are expensive. I would rather pay 50$ more per month for a bigger instance, than pay a few thousand to try and optimize the code so much or use a more efficient programming language but with features or libraries that are not so widely available.
There is a reason why many web apps run on Java or JVM-compatible languages (Spring, Spring boot, Play), even high-profile ones.

Collapse
 
siy profile image
Sergiy Yevtushenko

Spring and Hibernate are two main reasons why Java considered "memory hog" and "slow". Applications built without these frameworks usually fast and consume reasonable amounts of memory.

Collapse
 
sahilpabale profile image
Sahil Pabale

Yes it's just that many newbies are scared of those class names. Even i was but then i dived deep into learning Java and found it pretty amazing!

Collapse
 
michelemauro profile image
michelemauro

Most of the reasons you cite:

  • are getting fixed in the recent releases (switch expressions, road to pattern matching, records)
  • are problems unrelated to the languages but derived from external conventions or specifications (not every object needs to be a JavaBean with all getters and setters; and nowadays, almost none)
  • can be solved with some specific projects (Quarkus will take your web application and make a native container that starts in 1/10th of the time and uses 1/10th of the memory)

More than that, there is no reason to hate almost any language: every language has its history, its ecosystem and its peculiarities. There is a problem only when you can't choose a language that is better suited to the job you have to do.

Moreover, Java has a very, very solid and high quality ecosystem, that is tamper-resistant by design: it is very, very hard to publish a java library that contains malicious code and getting away with it, because it is very difficoult to publish something on Maven Central without giving them a really good idea of who you are.

So, there are many jobs and use cases where Java is an excellent choice, and a pleasure to work with. And there are other options (Kotlin, Scala, Groovy) if you want to access the same ecosystem but want less OOP, more FP or simply less syntax.

Just keep on codin'!

Collapse
 
totally_chase profile image
Phantz

Yeah, pretty much. Java has already realized that the world has moved on, and it has started to move on as well. The new features are so beautifully functional. It's great that Java is taking a few pages from the C# book. Though even with said features, I'd pick kotlin over java any day.

The problem, though, with any mainstream language, that is widely inferior but impressively improving, is adoption. The deed has already been done. The industry is mostly bound to the ugly chains of Java 8, and not many of them are going to upgrade.

Collapse
 
michelemauro profile image
michelemauro

More recent surveys paint a slightly different picture: Snyk JVM Ecosystem Report 2021 Finds Increased Usage of Java 11 in Production.
It looks like 11 has already surpassed 8 in production. And everone is waiting for 17.
Maybe they are waiting more for the JVM than the language, but Java remains an approachable and solid solution for many use cases and many teams.

Collapse
 
sahilpabale profile image
Sahil Pabale

Yeah you are absolutely correct😊😊

Collapse
 
siy profile image
Sergiy Yevtushenko

Try functional style with Java and you will see how concise and expressive Java could be.