DEV Community

Cover image for Pitch me on Java
Ben Halpern
Ben Halpern Subscriber

Posted on

Pitch me on Java

Continuing the series! Feel welcome to dip in and weigh in on a past question.

Let's say I've never used Java before. Can anyone give the run down of what the language does and why you prefer it? Feel free to touch on drawbacks as well.

Top comments (60)

Collapse
 
kithminiii profile image
Bhagya

Pros of Using Java:

  • Simple
  • A Secure Language
  • Cheap and economical to maintain
  • Platform-independent
  • Java provides an efficient memory allocation strategy

Cons of Using Java:

  • Slow and Poor Performance
  • Poor GUI
  • No backup facility
  • Significant memory space required
  • Verbose and complex code
Collapse
 
siy profile image
Sergiy Yevtushenko

Java is not slow.
Java is not for desktop apps.
Java is reasonably verbose, which makes support and maintenance of long-living projects much simpler. As a consequence, Java dominates enterprise software development. Needless to say that it means virtually infinite number of jobs, constant high demand and great salaries.

P.S. Java is very expressive and simple language with very straightforward, consistent and well thought out syntax.

Collapse
 
saptakbhoumik profile image
SaptakBhoumik

I don't think it's performance is bad compared to other interpreted languages. Sure it is slower than compiled languages but very fast for most task. Also what do you mean by no backup facility?

Collapse
 
stealthmusic profile image
Jan Wedel

I can only second that. Performance is actually very good, in fact it outperforms natively compiled C++ code in many situations as the hotspot VM aggressively optimizes at runtime.
Also I don’t understand what β€žbackup facilityβ€œ means.

Collapse
 
ivan_jrmc profile image
Ivan Jeremic

I never coded in Java but used many internal developed Java softwares and every single one was slooow. We had the same app later rebuilt with Electron which was fully written in JavaScript/Node and it felt like 50 times faster.

Thread Thread
 
siy profile image
Sergiy Yevtushenko

Slow apps could be written in any language. Java is not an exception.

Thread Thread
 
leob profile image
leob

Those "internally developed Java softwares" were likely desktop apps ... let's be frank, Java on the desktop (applets, JWT, Swing and all that) sucks ... do not, I repeat do not, use Java on the desktop - should only be used server side!

Thread Thread
 
abhinav1217 profile image
Abhinav Kulshreshtha

@ivanjeremic

We had the same app later rebuilt with Electron which was fully written in JavaScript/Node and it felt like 50 times faster.

If you think electron was faster, you can't imagine the performance of tauri, or webview.

I have worked on Java desktop app. They can be really fast if you compile it for production, which uses compiler optimization flags. Yes startup time can be slow in some cases, but JVM has been improving a lot in past few years. Memory footprint of J9 is also in league of its own.
It also depends on framework used, In my experience, If animations are avoided, Fx is really fast, compared to swing. That said, Swing is really performant library. Eclipes IDE uses SWT which is built upon on swing.

Thread Thread
 
leob profile image
leob

Good to hear a bit of a different view, the huge amount of bashing that Java gets (often not based on actual knowledge) can be tiresome ...

Collapse
 
leob profile image
leob

Sorry but it's not an "interpreted language", not by a stretch ... it uses a JIT compiler, once a piece of code (class or method) has been JIT-compiled it essentially runs almost at C/C++ speed (well, with still some runtime overhead in the form of garbage collection and all that).

Thread Thread
 
saptakbhoumik profile image
SaptakBhoumik

I know that. I am just comparing it's speed with an interpreted language

Thread Thread
 
leob profile image
leob

Right, well then you know it's not in the same league :)

Collapse
 
siy profile image
Sergiy Yevtushenko

Java is Just-In-Time compiled language. It's performance comparable or even better to compiled languages like C or Rust.

Thread Thread
 
ivan_jrmc profile image
Ivan Jeremic • Edited

I know that JavaScript is a JIT language it is comparable but not faster it can however have a few areas where it is as fast as compiled or faster, but most of the time just comparable.

Thread Thread
 
siy profile image
Sergiy Yevtushenko

JS as a language has some specific (variable type may change at run time, for example), which makes efficient JIT compilation somewhat tricky.

Collapse
 
bigbott profile image
bigbott

Kindergarten here.
When Java became interpreted?
Go to school, take some lessons.

Thread Thread
 
saptakbhoumik profile image
SaptakBhoumik • Edited

Before arguing properly READ WHAT I SAID. I am just comparing it's speed to an interpreted language.

Thread Thread
 
bigbott profile image
bigbott • Edited

You don't have problem with Java alone, but with English and languages in general.

Sentence: "I don't think it's performance is bad compared to other interpreted languages." states that you think that Java is interpreted language.

Thread Thread
 
saptakbhoumik profile image
SaptakBhoumik • Edited

Listen comparing java's speed with an interpreted language doesn't mean that I think it is an interpreted language. That like saying fighter jet is sound because we often compare it's speed with sound(mach number literally means number of times faster than sound). So instead of arguing(in this case you are completely wrong) do something useful or maybe learn english and how to behave online

Thread Thread
 
bigbott profile image
bigbott • Edited

Ok. Let me give you kindergarten level example.

I think that Ferrari is fast compared to OTHER bicycles.
Word OTHER here means that Ferrari is a bicycle. Otherwise, it completely redundant.
I hope you finally learned something.

Also, you don't actually need to think about Java performance. Just check some benchmarks. For example: github.com/kostya/benchmarks. You will see that Java between fastest and for some tasks Java is the fastest language. And its main competitors are C, C++, Rust and Go. Are those interpreted in your opinion?
You will also see, that comparing Java to interpreted languages like Ruby, Python and PHP is meaningless as its performance usually ten times higher.

Opinion that Java is slow comes exclusively from "new language of the day" propagandons and aimed into idiots who tends to believe everything they read more than once.

Collapse
 
leob profile image
leob

"Slow and Poor Performance", "Poor GUI", "No backup facility" - are you talking about Java on the desktop? (applets, swing, JWT) ... that's a disaster, and always has been, but Java on the server is a different story, it'd well-respected.

(scalability and memory management of the JVM in server environments are arguably strong points ... verbosity of the language remains an issue, but you can use other languages on top of the JVM)

Collapse
 
bigbott profile image
bigbott

Slow and poor performance? Where is it came from?
Compared to which language? JavaScript? Python? Ruby? PHP?
Do you have a benchmark?

Java is among fastest languages. For some tasks it is comparable to C++. With much simpler memory management.

Verbose - yes, but it is feature. All your fancy JavaScript oneliners should be well commented to be understood. Java code that follows conventions is self explained.

Writing GUI is not simple in Java, but it is possible. Check Eclipse and Netbeans. Those apps are among most complex GUI applications you ever seen and they written entirely in Java.

Collapse
 
thexdev profile image
M. Akbar Nugroho

Apache Cassandra is written in Java and it's fast πŸ€·β€β™‚οΈ

Collapse
 
scottshipp profile image
scottshipp

Java is a great language to learn and use for the following reasons:

  • It is one of the most widely-used languages there are, consistently placing in the top three most popular alongside C++ and Python

  • It powers most of the major web apps you know--everything from Twitter to Google Maps to eBay

  • As a result, it has a huge ecosystem of open-source libraries and frameworks around it. You can leverage the advantages of widely-used and well-maintained libraries for every kind of programming task imaginable from concurrency to testing (caveat: this also means you can experience analysis-paralysis about which library/framework to use to accomplish a task)

  • It has great performance and scalability, particularly in web services and applications (caveat: it is slow to load and does not support autoscaling as well as a language like Go)

  • Java is always backwards-compatible, even across major versions, so code that was written twenty years ago can (and does) still do its job today (caveat: this sometimes means it is slow to adopt modern language features or does so in unexpected ways)

  • A real advantage of Java is not the language itself, but the Java Virtual Machine. The JVM both allows Java to run atop any underlying hardware (you can run Java on your phone or your microwave, for instance) and allows you to use wholly other languages like Clojure, Kotlin, Scala, etc. in case you prefer a different idiom (functional, for example)

HIH

Collapse
 
taijidude profile image
taijidude • Edited

Pros:

  • Lots of jobs - a lot of companies use java
  • Performance - javas bad reputation is not really justified. Sure, it's slower than c or c++ but it outperforms python and Javascript, and php.
  • Lots of stable libraries
  • Static typing
  • Under active development with some big companies behind it.

Cons:

  • Verbose
  • Standard Libary could be better
Collapse
 
abhinav1217 profile image
Abhinav Kulshreshtha

Verbosity is not a bad thing. There is no behind the scene magic, which means you are in control, and can optimize code and its performance. Also in large enterprise, verbosity is encouraged because it will make it easier for the next guy who will replace you, to understand what is happening in code. Some companies even have code guidelines that prefers you to not show-off your special tricks and stick to basics.

At beginners level, With verbosity, you will learn concepts at a great details because you have to write every step of that concept. Every line of code that you write, you will ask yourself "have I covered all edge cases"

At intermediate level, your IDE will take care of a lot of stuff for you, You will have learnt the reason for any line of code you have written. So you will create generic snippets, and write a lot more code by writing a lot less.

And once you reach advance level of skillset, you will look beyond IDEs, You will use libraries like project lombok to replace boilerplate code with rich annotations. You will embrace annotations because you know what code compiler will generate based on those annotations. You will play with different JVM flags to optimize bytecode. All because you have a clear understanding of code that was verbose.

Collapse
 
leob profile image
leob

Probably what you abhor is the verbosity - that got quite a bit better with the most recent version(s), but still ... there's also a culture in the Java world of being in love with 'patterns', with layers upon layers upon layers, and with over-engineering in general ... I worked with Java for a long time, but for me moving to other languages and ecosystems was a breath of fresh air.

Collapse
 
liamjoneslucout profile image
liam-jones-lucout • Edited

You've really hit the nail on the head here. I'm working with a Java dev on a Typescript project at the moment and he's really struggling to get out of this mind set. Especially wrapping everything in a class

Thread Thread
 
leob profile image
leob

Yep ... :)

First thing he needs to do is forget and unlearn the heavy OO baggage, and throw that thick "patterns" book (the infamous "Gang of Four") out of the window ;)

Collapse
 
codewander profile image
codewander

test induced design damage

Thread Thread
 
leob profile image
leob

Lol and that is? TDD (if that's what you mean) is generally a commendable technique, it's not necessarily the reason why all of the Java software got so complex, it's more the mindset that everything needs to be infinitely generalized and abstracted to death, even when there's no reason to do so.

Thread Thread
 
codewander profile image
codewander

dhh.dk/2014/test-induced-design-da... - that was the article that got me thinking that hexagonal architecture, which I first encountered in reading about java (and scala) patterns, was part of a pattern of over engineering in some circumstances.

Thread Thread
 
leob profile image
leob

Ah right, interesting article ...

The problem is the misconception that all tests must be "unit" tests in a pure sense - no database, no I/O, only calculations ... that's of course nonsense and impractical, and that's not what TDD says.

If you accept that a large part (the largest part) of your tests just execute web requests (but without talking to a real web server over the network), and use a (test) database, then TDD can still be applied perfectly well without having to use Hexagonal or such extreme stuff.

So I'd say don't blame TDD, blame people who don't understand how to implement it in a practical way. Oh and Hexagonal Architecture is cool and interesting, and very relevant ... for less than 5% of all apps/systems ;)

(the 5% is almost certainly an exaggeration)

Collapse
 
tobhai profile image
Tobias Haindl

It is a robust and solid programming language.
You can build web APIs, Android applications and even GUIs with it.
The ecosystem is great and very mature!
There are well maintained libraries for nearly every use case.

Collapse
 
michaelfmnk profile image
Michael Fomenko • Edited

Pretty much every problem in Java has already been solved.

Literally, for every possible problem, there is a tutorial, library or research.
Anything from wrappers for some esoteric legacy protocols, to using existing C++ libraries.

Java is pretty much a 34 rule of programming. If some problem exists, there is a Java solution for that.

Collapse
 
abhinav1217 profile image
Abhinav Kulshreshtha

Java is pretty much a 34 rule of programming. If some problem exists, there is a Java solution for that.

This is so true, it made my day. 🀣

There have been many times, when I was working on PHP, or Node, I was stuck and closest thing I found was a java solution. It is easier to understand because of its verbosity, and convert that solution to whatever stack I am working on.

Most recently, I was working on a Golang project, and was stuck trying to refactor a very large module. I found an article on DZone about a similar example, I printed out the code, and implemented the structures based on that. Now my teammates are piggybacking on the improved package I wrote.
Funny thing is that this is the first time I am working with Golang, in a job. I have just learned Golang last year, and basically made a few contributions on various oss project on github. But my team is very happy to work with me, all because of Java.

Collapse
 
fnh profile image
Fabian Holzer

Disclaimer: I am a card-carrying member of the Boring Technology Club and my pitch might sound a bit like "nobody gets fired for buying IBM", but Java is a total work-horse.

It is not pretty. It is not best in class. But it is solid and has you covered. But you can draw from a vast pool of resources, have plenty of software engineers with experience to hire, there is an abundance of libraries. Its ecosystem is mature. All the stuff that makes you productive is in place.

I build software for hospitals for a living. I like to sleep well. I use Java.

Collapse
 
stealthmusic profile image
Jan Wedel
  • It’s a very good language for backend web applications (because of libs, frameworks and static type system)
  • Itβ€˜s ecosystem is very good (libraries, support, testing like junit, testconteiners, spring integration tests etc)
  • it’s constantly evolving with new features while keeping backwards compatibility

If you’re into something longer, I wrote about it here…
dev.to/stealthmusic/java-is-dead-l...
…and here…
dev.to/stealthmusic/modern-java-de...

Collapse
 
saptakbhoumik profile image
SaptakBhoumik

Write once run anywhere without recompiling. Coming from c++ that's a good addition

Collapse
 
michaeltharrington profile image
Michael Tharrington

@goyo I'm calling you out! I know you got some thoughts on this topic. πŸ˜€β˜•οΈ

Collapse
 
goyo profile image
Grzegorz Ziemonski

Well, a lot has been said here already but I'll chime in.

Java, especially the newer versions, is a very good language for server-side applications - it's fast, reliable, has powerful tooling and libraries, and virtually every question you may have has already been answered online.

On the other hand, it is not the most sleek language so if someone really cares about punctuation or the number of characters they have to write, they may be put off.

The language is ubiquitous among enterprises, so it's a pretty solid bet if you want to get a job or switch companies. It also means you're likely to work with enterprise applications and deal with complex business issues. IME, if you're biased towards solving interesting domain problems, you'll be happy doing it with Java (and probably any other language). If you're more biased towards doing cool technical stuff, you're probably going to look for something else.

Personally, I'm in love with Kotlin and I see it as an obvious replacement for Java, as they work in the same ecosystem.

Collapse
 
codewander profile image
codewander

I have been trying to find statistics on Kotlin backend adoption. I don't have a good way of measuring it right now. I see it occasionally in backend job descriptions. I suspect it will take over java marketshare, but not sure.