Java certainly isn't shiny and new like Swift or Kotlin. But it's not any less attractive than C, C++, or Visual Basic which are all listed ahead of it in the article. So I disagree with the premise. Yes, Java's popularity is shrinking but not at a concerning rate.
If I had to name one missing language feature that imperils Java it would be the lack of compiler-checked null-safety. After using both Swift and Kotlin this is a feature I dearly miss in Java.
> Managing code decorated with Java getters and setters is hell and complicated. The lack of a meaningful solution to the problem of getters and setters is just the tip of the iceberg.
I don't use Java much these days, is this a huge issue still? Back when I used to do a bit of light java, mainly dealing with minecraft server plugins, almost everyone used lombok which seemed to do the job.
There are libraries like Lombok that will generate the getters/setters for you via annotations. But tbh still feels very cludgy.
Why not add some first class immutable structure syntax to avoid need for getters/setters at all. Just so many better languages to choose from these days, Java is too far behind. And where they bridge the gap, they tend to do it in an awkward way.
Just the idea of writing getters and setters that don't actually do anything at all, except to allow access to a 'private' variable, makes me want to tear my hair.
The language design failure that get/set methods are used to monkey patch around is the lack of computed properties.
If you have an object with properties A and B, but later realize that B can be calculated from A, it would be nice to eliminate the class of "Inconsistent A and B Values" bugs from your software, by making B calculated from the value of A. The problem is, without computed properties, that involves replacing the Object.B expressions with Object.getB() expressions, breaking your API.
So Java developers got in the habit of putting getters and setters on everything.
I don't think that rationale makes a lick of sense in code written today.
Besides the obvious violation of the YAGNI-principle and stinky mixture of data and logic, even if this scenario arises (which it very rarely does) any Java IDE worth its salt can replace a variable access with a method with a few mouse clicks.
Exactly! And the solution is don't write getters and setters unless you are absolutely forced to do so, and even then only for the minimum amount of fields.
Lombok requires undocumented compiler internals, and explicit IDE support. There is thus functionally no difference between Java with Lombok and a separate language, at which point there's no reason to not use Kotlin directly.
I learned Java in the 1990s and heard that there would be CPUs with Java. Today, My Raspberry Pi has such a chip. JDK gets installed with one the distros I use. I can run Java on a variety of platforms if I want.
The reasons I avoid Java:
* too many large updates in the past for vulnerabilities.
Java is in the awkward middle ground where a lot of popular companies are using more specialized languages and startups are free to use whatever the founders want.
So, a lot of companies that are older, stable, and risk averse are using Java. This means Java isn't very exciting and it clearly doesn't have the 'pop' on a resume other 'cooler' languages do.
I don't think many people spinning up a new project will use Java. Go and C# are newer, often faster, and are just as full featured, not to mention Node/Python.
This doesn't mean Java is a dead end. I think a lot of Java concepts are pretty transferrable to other OOO languages, and because of the stability and longevity, it's a language you'll be able to find a lot of jobs with.
I read the article and don't find any of the points compelling. I think it has more to do with factors other than the language itself. For instance there are other languages both using the JVM and not with good frameworks.
Perhaps Spring Framework/Boot is declining in popularity, but that's just wishful thinking--and my real beef is with Hibernate+JPQL.
Oddly Java itself as a language is better than ever and still improving.
The thing I heard was that it was easy to hire Java devs, maybe that availability has been consumed and there aren't competent Java devs in the market like there used to be. So effectively the hiring pool doesn't know Java.
> A second data point is: other languages improved enough, Java is just another one among many.
To me, C# not only caught up with Java, but also overtook it and left it miles behind. Developing services with .NET Core is an absolute pleasure, and feels so effortless.
Beyond tradition and legacy code, what does Java have to offer?
We're happily writing everything Java in 2022. We have quick development turnaround, developer productivity, high execution speed, simplicity, reliability, and transparency. CDI, Tomcat, JAX-RS, slf4j, JPA, Junit, Mockito, Hawtio, Maven, ActiveMQ are all things we leverage. Everything is monitored in production, and we handle thousands of messages per second and thousands of requests per second, all on modest hardware. Deployments are super simple too: everything is packaged up as a native Debian package using the JDeb maven plugin and is a one touch install. Isolation is done using systemd, avoiding the rat race and un-needed complexity of docker and other complicated tech.
We easily push 1 million messages per second with a 512m heap and two cpu cores, and 80m of heap to applications... so I'm not sure what about that is "heavy" or "unsuited" but... I mean ok. We also spent 0 time trying to optimize this because it's so fast by default.
This is actually a big thing for me, even though you can auto generate with IDEs, Java feels very verbose, even when using the Stream operators.
I just learned C# 2 years back and it opened my eyes to basically Java with less boilerplate. Now with ASP.NET, it's the same thing. It's Spring Boot with less boilerplate and more streamlined.
I push new projects to use .NET as much as possible.
My guess is that Java is becoming less popular because nobody wants to maintain someone else's legacy code. If you only admit to knowing a recent language you get to write your own new code in that language. Then eventually the new language will accumulate cruft (features) and become the old language and the same thing will happen again. It took a long time for FORTRAN to be replaced by C and C++ and for those languages to be partially replaced by Java. Java is being replaced in an even shorter time frame. It's part of the trend of scrapping the past rather than improving it and making it more stable. In some cases that is a good thing, in others it destroys things.
Dunno, maybe it's the stockholm syndrome talking, but I like Java.
The most glaring problems with the language are actually being addressed, and beside that, the tooling is amazing and the ecosystem is very mature and stable.
I only wish they would hurry up with the foreign memory API. Because only being able to memory map 2 Gb at a time is a pain in the ass than yesterday's vindaloo.
Is there a reference for the language ranking chart they use? I didn't see one listed. They have VB listed above Java, which I cannot believe is true. Is it including all the Excel macros out there in the world?
I referenced the Tiobe Index, and it has Java at #3. So, who knows?
In my experience Java is used a lot in "the enterprize", and that's the kinda environment which isn't fun to live in. Lots of designs by committee, and lots of boilerplate coding.
The question should be: Why WOULD anyone want to learn Java in 2022? It’s not at the front of any trends that young people care about.
It’s not the go-to language for anything related to data science or ML, or webdev, or getting a job at FAANG. I’m not even sure it’s possible to write an Android app in pure Java anymore.
All this stuff about Oracle owning the IP or being mad about getters and setters is just internet people ranting to get their quick anger fix.
I recently tried Java, and attempted to use Spring Boot, EE, Jetty, etc, to setup a small service-oriented cloud app, and I must say, the barrier to getting it up was a more effort than compared to the ecosystem of Node, Deno, Python. Even the package manager Gradle was not as quick of an effort as other PMs.
This is a much better framework to get up and running quickly with Java, especially with my background using Node. But the effort finding this was substantial, it is not widely broadcasted. Tomcat seems to be the dominant path, but I feel Tomcat is overkill for a small, personal use case where I just want to try some ideas out.
Even after finding Javelin, I still found some resistance to getting the classes to work together and getting it properly bundled.
I should also note I'm not interested in the IDE automation scripts that do everything for me (a few YouTube Java tutorials show quick-starts with Eclipse, Lombok). I want to understand things and don't enjoy "magic" bootstraps that hide a lot of detail. I prefer less bloat from dependencies.
Java is great for complex monolithic applications. It is however a bad fit for serverless architecture, it has terrible support for JSON, the new HTTP API is slow (really slow) and websocket support is poor. Electron has easily won the cross-platform UI battle. The world moves fast and Java evolves at a snail's pace.
Static Typing [...] other languages, such as Scala and Haskell, offer some form of type inference
Okay, so Java has the var keyword, which does type inference and has been around since version 10 (4 years now). And it's not like people don't like statically typed languages... ever heard of a little thing called Rust?
Also, as has been mentioned, getters and setters were fixed through the introduction of Records in Java 14 (2 years ago).
The example code for exceptions is kind of weird, as the author mentions the throws list, but doesn't have any throws declarations in there; and in try catch you can just catch Exception ex to have a default handler. And it wouldn't make sense to complain about having to catch new exceptions if you want to handle those exceptions separately. In fact it doesn't make sense to blame Java for breaking API changes, those can happen in any language.
45 comments
[ 3.0 ms ] story [ 113 ms ] threadIf I had to name one missing language feature that imperils Java it would be the lack of compiler-checked null-safety. After using both Swift and Kotlin this is a feature I dearly miss in Java.
Unless the project is already partially built in Java
I don't use Java much these days, is this a huge issue still? Back when I used to do a bit of light java, mainly dealing with minecraft server plugins, almost everyone used lombok which seemed to do the job.
Why not add some first class immutable structure syntax to avoid need for getters/setters at all. Just so many better languages to choose from these days, Java is too far behind. And where they bridge the gap, they tend to do it in an awkward way.
Most of these bridge features are hobbled by BC concerns. E.g lambdas, generics
It's boilerplate for the sake of boilerplate.
I code primarily in Java, and I can't really say the last thing I wrote a getter or a setter, except possibly because I wanted a functional reference.
Accessor methods is part of a style of code Java that was unfashionably outdated 10 years ago.
If you have an object with properties A and B, but later realize that B can be calculated from A, it would be nice to eliminate the class of "Inconsistent A and B Values" bugs from your software, by making B calculated from the value of A. The problem is, without computed properties, that involves replacing the Object.B expressions with Object.getB() expressions, breaking your API.
So Java developers got in the habit of putting getters and setters on everything.
Besides the obvious violation of the YAGNI-principle and stinky mixture of data and logic, even if this scenario arises (which it very rarely does) any Java IDE worth its salt can replace a variable access with a method with a few mouse clicks.
Now, in 1995, maybe...
The reasons I avoid Java:
* too many large updates in the past for vulnerabilities.
* two large corporations extinguished Sun Java.
So, a lot of companies that are older, stable, and risk averse are using Java. This means Java isn't very exciting and it clearly doesn't have the 'pop' on a resume other 'cooler' languages do.
I don't think many people spinning up a new project will use Java. Go and C# are newer, often faster, and are just as full featured, not to mention Node/Python.
This doesn't mean Java is a dead end. I think a lot of Java concepts are pretty transferrable to other OOO languages, and because of the stability and longevity, it's a language you'll be able to find a lot of jobs with.
Perhaps Spring Framework/Boot is declining in popularity, but that's just wishful thinking--and my real beef is with Hibernate+JPQL.
Oddly Java itself as a language is better than ever and still improving.
When I saw that reason 1 was "Java Is Becoming Less Popular", I had to scroll back up and reread the question. OK - kinda circular.
Then I chuckled when I released it's the other side of "We use Java because everyone knows Java" that I've been hearing for years.
The fact that it is associated with one of the most scummy companies in the planet doesn't do the language any favours.
A second data point is: other languages improved enough, Java is just another one among many. There's nothing unique about it.
I don't want to touch anything associated with Oracle, because that company is predatory.
Ask companies whose employees made the mistake of installing VirtualBox plus the extension...
To me, C# not only caught up with Java, but also overtook it and left it miles behind. Developing services with .NET Core is an absolute pleasure, and feels so effortless.
Beyond tradition and legacy code, what does Java have to offer?
Java is not feasible to work in that world. JVM is too heavy to do that.
Modern languages like Go are much better for that. If I recall correctly soon half of all new projects will start as a Go project.
How long will it take to scale out?
How easy it is to write event driven architecture, can ppl pick up the code in two days and become efficient?
Java has issues that other languages requiring a bit more grunt work dont have.
I just learned C# 2 years back and it opened my eyes to basically Java with less boilerplate. Now with ASP.NET, it's the same thing. It's Spring Boot with less boilerplate and more streamlined.
I push new projects to use .NET as much as possible.
I am from the international church of record.
Do you have time to talk about our lord and savior `record classes`?
https://docs.oracle.com/en/java/javase/15/language/records.h...
The most glaring problems with the language are actually being addressed, and beside that, the tooling is amazing and the ecosystem is very mature and stable.
I only wish they would hurry up with the foreign memory API. Because only being able to memory map 2 Gb at a time is a pain in the ass than yesterday's vindaloo.
I referenced the Tiobe Index, and it has Java at #3. So, who knows?
It’s not the go-to language for anything related to data science or ML, or webdev, or getting a job at FAANG. I’m not even sure it’s possible to write an Android app in pure Java anymore.
All this stuff about Oracle owning the IP or being mad about getters and setters is just internet people ranting to get their quick anger fix.
I recently tried Java, and attempted to use Spring Boot, EE, Jetty, etc, to setup a small service-oriented cloud app, and I must say, the barrier to getting it up was a more effort than compared to the ecosystem of Node, Deno, Python. Even the package manager Gradle was not as quick of an effort as other PMs.
But then I found Javelin, https://javalin.io/
This is a much better framework to get up and running quickly with Java, especially with my background using Node. But the effort finding this was substantial, it is not widely broadcasted. Tomcat seems to be the dominant path, but I feel Tomcat is overkill for a small, personal use case where I just want to try some ideas out.
Even after finding Javelin, I still found some resistance to getting the classes to work together and getting it properly bundled.
I should also note I'm not interested in the IDE automation scripts that do everything for me (a few YouTube Java tutorials show quick-starts with Eclipse, Lombok). I want to understand things and don't enjoy "magic" bootstraps that hide a lot of detail. I prefer less bloat from dependencies.
Okay, so Java has the var keyword, which does type inference and has been around since version 10 (4 years now). And it's not like people don't like statically typed languages... ever heard of a little thing called Rust?
Also, as has been mentioned, getters and setters were fixed through the introduction of Records in Java 14 (2 years ago).
The example code for exceptions is kind of weird, as the author mentions the throws list, but doesn't have any throws declarations in there; and in try catch you can just catch Exception ex to have a default handler. And it wouldn't make sense to complain about having to catch new exceptions if you want to handle those exceptions separately. In fact it doesn't make sense to blame Java for breaking API changes, those can happen in any language.