[go: up one dir, main page]

DEV Community

Cover image for Why I love Java
Arik
Arik Subscriber

Posted on • Originally published at Medium

Why I love Java

Java is unarguably one of the most popular programming languages in the world today. Companies like Google, Amazon and Netflix -- to name a few big names -- are using Java to build large portions of their infrastructure and backend services. But despite its huge popularity (or perhaps because of it) Java's reputation among programmers is something of a mixed bag. Some seem to genuinely like it while others hate it.

Personally, as someone who has been using the language for more than a decade professionally, I find it to be an excellent language. No, it isn't perfect. And the programming world -- being young as it is -- is still learning from its own mistakes. But all other things being equal I think that Java got a lot more right than wrong.

Following are some of the things I think Java got right:

It's a productive language

As a programmer I get paid to solve problems. In minimum time and maximum quality. My software is expected to be robust (bug free), performant and maintainable (easily extended). I typically write large, distributed and fairly complex server-side software.

Java is a purely Object Oriented language. To the uninitiated, this means that you design your code around unit of codes called "objects" which loosely resemble real-world object (or concepts). So if you were to write, say, a library management software you'll most likely have these code objects representing books, members, staff but also more abstract concepts such as genre and loan.

This happens to be a very neat way to organize software (and your thoughts). Instead of thinking about your system as a big line-by-line, step-by-step algorithm, you think of it as a set of interacting objects. If done right, each one of these objects can be reasoned about independently from other objects. Each object can be tested in isolation from others and each one can be extended without necessarily affecting the entire system.

Java did not invent the idea of Object Oriented Programming. In fact OOP dates back to the late 60's, but the Java language designers did a great job implementing the idea in the language in such a way that it is practical and productive for the programmer.

The Java Virtual Machine

One of Java's most convenient features is the Java Virtual Machine (or JVM). The JVM essentially acts as the translator between your Java code and the particular operating system that your code is running on. This is the origin of the once-famous Java marketing slogan "write once, run anywhere". Without the JVM, you'd have to compile your code for every operating system separately. the JVM guarantees that your Java code runs identically on Linux, Mac or Windows.

The Java language designers also envisioned a world where other languages can execute on the JVM besides Java. To that end they've specified a low-level language (called "bytecode") which is the language that Java complies into and the stuff that actually gets executed on the JVM. Today there are dozens of languages targeting the JVM as a result.

Automatic Memory Management

If you ever used a language such as C or C++ then you are intimately familiar with the painstaking effort involved in manually managing memory allocation (and deallocations) in your programs. This is an area, so rife with bugs that the designers of the Java Programming Language decided to do away with it completely. Rather than giving the programmer the opportunity to shoot themselves in the foot they decided to let Java do all the memory management for them -- automatically.

In Java, the programmer simply creates whatever objects they need (without explicitly worrying about allocating memory for it) and Java will automatically reclaim that memory once the object is no longer used by the program.

Standing on the shoulders of giants

Java was designed and implemented by some of the brightest people in the Computer Science world. People such a Doug Steele, Joshua Bloch, Mark Reinhold and Brian Goetz are true masters of their craft and are a constant source of inspiration and learning for me. Not just about Java per se, but more importantly, about writing better software in general.

Huge community

As of this writing, according to Wikipedia, there are 9 million Java developers around the world. This is a huge advantage because for just about every problem you run into as a developer there is a high likelihood that someone, somewhere had already solved a variation of this problem or that very same problem. Usually a simple online search will reveal multiple sources that can be used to solve or at the very least approach the problem.

Fantastic frameworks & libraries

Java has an enormous array of frameworks and libraries to choose from. From logging, to web development, to database connectivity, to messaging clients, there's a library (or several) to help solve just about any problem. A particular favorite of mine is the Spring Framework which had become the defacto framework for any sort of work involving web (HTTP) technologies.

Writing web application using "raw" Java would be a tedious task, to say the least. Moreover, the designers of Spring noticed that many programmers are trying to solve the same (or very similar) problems and each one is solving these problems slightly differently. Spring (and its vast portfolio of sub-projects) are meant to give the programmer a leg-up by giving them a solid set of building blocks to build upon for their projects.

Closing thoughts

There are many fine languages to choose from out there. Java is just one of them. This article is in no way trying to claim that "Java is the best" or that "Java is better than X language". It is simply meant as an acknowledgement to the fine work that made Java possible.

Top comments (31)

Collapse
 
bzitzow profile image
Brian Zitzow • Edited

As someone who has used Java, Ruby, Scala, PHP and JavaScript in a professional setting ... I chuckled a little bit when reading this. It has not been my experience that Java is productive. Quite the opposite, really. When compared to Ruby and JavaScript, the framework and libraries in Java are dismal.

Doing anonymous functions in Java is painful.

The same is true for concurrency.

Jave only recently got a REPL, with Java 9, and if you are working on an existing software platform, the chances you have access it Java 9 are small.

The JVM isn't bad ... But it's a memory hog, and I'm having a lot of fun and continually impressed learning about the erlang virtual machine. When compared to an imperative language, the JVM is definitely fast, so that's good.

You said you have used Java for the past 10 years ... I noticed you didn't compare it to any other languages, communities or development ecosystems...

Collapse
 
mechtecs profile image
Max Schorradt

Java 8 added anonymous / lambda functions, to easily define functions for e.g. EventListeners, without specifying a class and overriding a specific method. I cannot talk much about the other languages considering concurrency, but JavaScript is by default single threaded in the user code. Multi threading is a hard effort. Same goes for PHP, which when I wanted to try it last time, was just too complicated. Java supported concurrency for a long time now, but you had to manage and write the algorithms to be threadable. Now with Java 8 you can just use streams for simple algorithms.

Collapse
 
bzitzow profile image
Brian Zitzow

Java 8 did add anonymous functions. Unfortunately, bolting features like this onto Java results in a "yes we can do this, but it feels really icky because the language wasn't designed to support this. Not really." kind of experience. It's very noticeable for anyone coming to Java who has experience in a language that was designed to support lambdas.

While I haven't really used Kotlin, a quick web search comes up with examples that show it reduces the boilerplate code by 40%:

medium.com/androiddevelopers/from-...

Another disappointment (I have) with Java's implementation with anonymous functions is their incompatibility with Checked Exceptions. Again this is a result of Java adding features it wasn't designed to do.

Just 2 weeks ago I had to refactor some code a developer wrote with the Streams API and anonymous functions because we encountered a need to depend on code that relied on CheckedExceptions - and it wasn't practical or feasible to rewrite it at this time.

Java is an Okay language. My only point is that I don't find it "productive" or "developer friendly" compared to the other languages out there, especially the newer ones.

The other reasons listed in this article aren't targeted at me, because I've not used C professionally and had to deal with memory management in one of those older languages. That being said, the other newer languages on the market also handle this stuff - it's not a unique value add Java brings in the current market.

Collapse
 
bzitzow profile image
Brian Zitzow

"Multi threading is a hard effort."

I'll agree with that. If you're really interested in concurrent and fault tolerant systems Elixir or erlang are worth checking out.

The erlang virtual machine supports the actor model as a foundational design and is time tested. They both enforce immutable data structures as well.

Go and Kotlin also tout abstractions that make it easier to deal with concurrency.

As someone that uses Java daily, I'm just saying - I don't see it. I don't see why it's so special anymore. It was special and useful and productive at a certain time period, but in my opinion, that period is gone.

There are better Java's than Java and there are plenty of other alternative modern languages that are very well designed.

Collapse
 
dean profile image
dean

People give Java a lot of crap for it's verbosity. I started using Kotlin and began to love it's conciseness, and slowly started to hate Java for how verbose it was.

But then I started learning Go, and learned the value of verbosity. It really does make code more readable and helps you understand what's going on. I now have a greater appreciation for Java, and it's verbosity.

Collapse
 
differentsmoke profile image
Pablo Barría Urenda

Sometimes verbosity is necessary to express an idea with enough nuance.

Sometimes verbosity is not what we, in the modern world, would call a necessity or a demand but rather an unnecessary addition of words born out of verbosity not necessity, what one would call an unnecessary verbosity which truly adds nothing to the original idea, that of verbosity being unnecessary, meaning it is unnecessary verbosity.

Collapse
 
dean profile image
dean

Go strikes a really nice balance between verbosity and conciseness. Java, I feel, could be a little more concise... All the ByteArrayOutputStream outputStream = new ByteArrayOutputStream() is a bit much, but other parts, such as not having true "properties" (and rather fields), is actually nice in my eyes.

Thread Thread
 
tomlincoln93 profile image
Gáspár Tamás

You mean:
var outputStream = new ByteArrayOutputStream()

? :)

Thread Thread
 
dean profile image
dean

Some of the machines I use can't update to Java 9 since it broke backward-compatability with using Java internal libraries, esp if I want to use tools like jd-gui

Collapse
 
mohamedelidrissi profile image
Mohamed Elidrissi • Edited

I think it was on the StackOverflow survey's top 3 most loved languages by developers and that's not surprising at all, but I still like java because it was the first programming language I learned and it was a lot of fun to work with

Collapse
 
tomerbendavid profile image
Tomer Ben David • Edited

I love java, I used Scala, JavaScript, python, R, typesceipt, Ruby, haskell, closure, and more professionalky. Computer language is just a tool, the product, system is the main thing and where the real challenge compelexity lays.

Collapse
 
remify profile image
Rémi B

I can't love Java because of other languages. Java is good and it can do many things but it doesn't shine anywhere it use to.

Collapse
 
schreiber_chris profile image
SCHREIBER Christophe

On the subject of memory management, developers should be aware of how the garbage collector works under the hood, because it affects the design of the code. Not having to care about freeing memory doesn't mean you don't have to care about memory management at all ;-)
I've seen many projects having poor performance because of memory leaks, leading to garbage collector running constantly and even the server crashing because the GC couldn't free enough memory (if I remember well, this occurs when GC is running 98% of the time to free less than 2% of the heap).

Collapse
 
shaijut profile image
Shaiju T

😄, I used to have questions like which language is better ? After discussing with my friends and listening to people online, I realized that Its better to stop asking these questions. Instead start asking which tool is better for current Job and Trend.

Choose the right tool for the Job.

  • Based on your experience, you can use C# or Java for building enterprise and large applications.
  • Instead JSF you can think of using Anuglar orReactorVueetc. for Front End.
  • Python for Machine Learning.
  • Go for Micro Services based performant applications.

In future maybe today's Languages and Framework may be outdated, so to survive you will be forced to learn new language of that time.

Conclusion:

  • Developer Happiness, stick to the language which make your life easier, like easy to read syntax, maintainable, has Good IDE. I like C# for current work, and its up-to you to decide what you like.

  • Its always good to be Open to learn any language as required and Choose the right tool for the Job.

Hope this helps.

Collapse
 
differentsmoke profile image
Pablo Barría Urenda

I have never used Java, but this was something of a red flag to me:

To the uninitiated, this means that you design your code around unit of codes called "objects" which loosely resemble real-world object (or concepts).

I'm a self taught dev, and I REALLY struggled with understanding Object Orientation early in my career. I once came across an article on "worst advise rookie programmers get" and listed in it was that this idea that "Objects are like things in the real world".

I'm really not trying to be a hater, but reading that that was a bad way of thinking about objects was the beginning of my grokking object orientation.

Collapse
 
andevr profile image
drew

I'm recently learning Java after struggling for a long time to learn JavaScript. I chose Java over Kotlin because I wanted the best chance of getting a job with my first language (way more available jobs) while also positioning myself to eventually learn kotlin/android development if Kotlin eventually takes over or becomes more prevalent. Java has been such a joy to learn, I've made way more progress with it than I ever made with my early attempts to learn a language.

Collapse
 
acoh3n profile image
Arik

That's really cool. And I totally agree on all points. Java is a great choice career-wise because it's in very high demand. It is also a pretty simple language and not overly loaded with features -- which to some might seem as a shortcoming compared to other languages -- but personally, I think that its simplicity is one of the language's biggest strengths. Good luck in all endeavors!

Collapse
 
andevr profile image
drew

Thank you. I think the simplicity is part of what draws me. In a lot of ways JavaScript was very complicated, and the lack of exercises in 99.9% of JavaScript learning material aimed at completely new people is more a hindrance than anything. Java is definitely more my speed, and having multiple opportunities to practice has made it a much better experience.

Collapse
 
henry701 profile image
henry701

Java is not purely an Object-Oriented language. It's mixed. Still, i got the point.

No points there about Java are wrong, but what i found is that most of the other similarly-used languages get those points right better than Java 90%> of the time. And when people compare it to other languages, that's why it comes out bad.

When comparing Java to C#, for example, i found it outdated because there are many features that really make developing more productive and code cleaner and that are purely syntax sugar, but Java does not implement those at all.

Collapse
 
bertilmuth profile image
Bertil Muth • Edited

As a long time Java programmer myself, I fully agree. I have learned to live with the downsides, and appreciate the upsides, e.g. having a decent type system. Sure there are lots of other languages with that as well, but there are also languages with inexplicable type casts - IMHO that is not helpful at all, but a constant source of unnecessary surprises.