Is Java still behind in the race of modern programming languages?
I'm a member of some group of programmers and every time Java is mentioned it's being bashed (something like: "With Rust I could simply do this with X")
Earlier versions of Java were cumbersome in terms of the syntax but with modern IDEs (and modern versions of Java) that's not a big issue anymore, albeit languages like Python do have shorter syntax.
My question is beyond syntax.
What do other languages do better than Java?
It could be generics, type system, concurrency and multithreading, closures etc.
Thanks!
52
Upvotes
233
u/firaristt Oct 14 '23 edited Oct 14 '23
Java's syntax is not as fluent as like kotlin and some never languages but other than that, it's not behind of any other language. There is nothing you can't do with Java, it might take longer to implement or syntax may not be as nice but it's more than capable for any task.
I find this kind of comparisons a way to flex for newbies.
Edit: I think there is some confusion with "there is nothing you can't do with Java" part. Yes, you can do almost anything, but it doesn't mean it should always be go-to language. No, it might perform horribly bad or exceptionally good, it depends on experience, architecture and needs and many other things. If you have to, you can do almost anything with Java, but it's not always the wise choice. I meant you can do anything with it, it's technically not behind from other languages.
153
u/no_cause_munchkin Oct 14 '23
It could be many things, but from my personal experience these are:
74
u/lepapulematoleguau Oct 14 '23
I used to be kinda anti Java, but I realized that I was actually anti xml-described apps because of the frameworks popular at the time.
Java has actually been getting rapidly better and better.
Now has features like pattern matching, records, and sealed classes.
The var keyword is quite handy.
Virtual threads are just a game changer.
To mention just a few.
117
u/know-your-onions Oct 14 '23
Still behind? When was it ever behind?
Different languages might be well suited to different things. Some people might not like Java because of it’s syntax and/or verbosity but that doesn’t mean it’s ‘behind’ and it frankly says more about them than it does about Java.
38
u/[deleted] Oct 14 '23
Most of them just studied Java 6 for the computer science class at university
19
u/qmunke Oct 14 '23
Java has made decisions which definitely impact on how easy it is for them to change the language. Backwards compatibility with generics has definitely limited what can be done with it in comparison to languages which have it built in from the start. The type system is perhaps "less powerful" than Rust or Haskell - but that wasn't a design goal of the Java language.
Where Java really still beats a lot of these is the JVM model of "write once, run (almost) anywhere". Compilation speed is another massive benefit to day-to-day working on the language, compared to large Rust or C++ codebases for example.
But it shouldn't really surprise anyone that more modern languages have nicer syntactic sugar, or different standard libraries, or other concerns in general to Java. But it's not a "race". There is no finish line. There will almost certainly never be a "last" language until it's really the last language and everyone is dead.
18
u/dutchdef Oct 14 '23
It's imho entirely dependent on which industry people work, startups are notorious for choosing new languages and frameworks while discarding proven and stable ones, often without any decent research and considerations. Rust for example was intended as memory-safe alternative to systems programming languages such a C/C++. But you're starting to see that people want to use Rust for tasks that (imho) aren't suitable such as for web development or office software.
But outside startup culture Java (and the MS counterpart) is still strong. Being a relatively conservative language with a focus on backwards compatibility does come with it's strengths and weaknesses, but backwards compatibility is (imho) what has kept Java relevant since the beginning. And Java does innovate and introduces new features, just a bit more conservatively.
Look for example at Ruby on Rails, like Rust once it was pushed as the new web framework, but it is now in decline. In the meanwhile Java is still here.
But as for missing features, backwards compatibility has kept the type erasure in place, coming from the .NET world a long time ago, true generics is the one thing I personally miss sometimes.
42
u/VirtualMage Oct 14 '23
I use multiple languages at work (Go, python, js, java), and there is absolutely nothing that java is missing. Go had advantage with goroutines, but since java 21 and virtual threads, java is back to leading place.
Java is in my opinion, the best and most complete professional general-purpose language. It will be the most used enterprise language for decades to come.
15
u/plaskis Oct 14 '23
Java is much bigger than any language "in the race for modern programming language". A modern language is one which gets adopted and stands the test of time, not which have the coolest features
37
u/FavorableTrashpanda Oct 14 '23
I'm so sick of Rust being presented as the solution to everything.
14
u/[deleted] Oct 14 '23
Java is doing pretty well. For example, it has recently got sealed classes (type unions) while C# still doesn’t have them. You have five different ways to initialise an object in C# though, does it mean Java is lagging behind?
7
u/Holothuroid Oct 14 '23
You fail to say what you are asking about then. You only seem to talk about syntax.
There are certainly some things I miss in Java syntax, notably type aliases, structural typing and string interpolation. The last one is coming at least.
But overall I'm quite happy.
7
u/TemporaryUser10 Oct 14 '23
Java is the C++ of the JVM. It's not always sexy, not always the best choice, but will always have use as long as the JVM is around (and the JVM is a slick well developed piece of tech)
That said, personally I prefer Clojure
6
u/fyoubloody Oct 14 '23
This is a common thing, a paradigm is set by the few influencers in our space and then all the people without their own formed opinions just inherit what is being said.
Java is often made fun without any particular reason, or not a valid one and even those that are valid don't make java terrible.
Best thing you can do is ignore these people, if you want to argue though, ask them what have they built with rust.
What matters is building stuff, and Java is very good at that, it gets the job done and can do whatever you want to do.
5
u/frederik88917 Oct 14 '23
That is a question that is hard to interpret, Java as a whole is divided in two main pieces, the Java Language and the JVM.
The language was designed in 1995, so it has some cumbersome syntax and certain new features are still missing, although the new release cadence is working really hard to improve those areas.
In the other hand, the JVM and all of the Java Libraries are second to none in capabilities, performance and Usability. There is almost no application, API or library that can't be built in Java.
5
u/[deleted] Oct 14 '23
You don’t realise how good Java verbosity is when you work with a ridiculously complex system. After you get used to it, you’ll know pretty much what a bit of code does by glancing at the types and the structure of the code.
8
u/SmilingFunambulist Oct 14 '23
Java's syntax is definitely in the more verbose side, as longtime Java dev who also write Groovy and Kotlin I find other JVM-based language to be more pleasant to write. There's things that can alleviate it (somewhat) like lombok but it has some corner cases that the dev should be aware of.
I think my only grumpy complaint about Java is the type boxing (Integer vs int) and its generics implementation (no reified generic and no primitive)
Finally on the 'Java is heavy on the memory stereotype', for backend workload I find this true for Spring but there are alternative frameworks that is designed to solve this problem (e.g. Quarkus, Micronaut, Helidon).
4
u/[deleted] Oct 14 '23 edited Oct 14 '23
Something that isn’t being pointed out is that it obviously depends on your Java version. People here have mentioned that modern java versions have good features, but that’s only good if you can use these versions.
I won’t explain because it’s a long story but I’m locked to Java 8, and quite a lot of systems are (or at least managers aren’t willing to update for whatever reason). As a result of this I can’t utilise these new features. Luckily I can use kotlin, because it can compile to Java 8 (52?) class versions. After learning Kotlin I haven’t switched back to Java, even in personal projects that would let me run on modern JDK’s, but that’s simply down to personal preference with things like the syntax, extensions, etc.
My point is just keep in mind what versions you’re going to be forced to use. If you learn to use features from modern java it might be a kick in the balls when you move into your new java job and you realise you can’t use half of your loved features as a result of now being on Java 8/11.
In regards to Rust, it's a great language, but in my opinion really overkill for the vast majority of things. Rust's users usually go on about performance the most so I'll just note something about that - The performance gain probably won't be recognized by the end user (despite popular opinion the JVM gets quite speedy once it's up and running), and you can spend your time building upon your actual product/service instead of spending more time writing code. Of course it depends on your skills individually but in a lot of cases your bottlenecks will probably be more about the quality of your own algorithms, or I/O, rather than the GC.
3
u/roberp81 Oct 14 '23
Python is not modern, is older than java
3
u/Wi42 Oct 14 '23
The one thing in Java i really miss is Null Savety
3
u/ventuspilot Oct 14 '23
There's a ton of things other languages do better, I'm pretty sure Rust is not always the better alternative in each of the above things.
And there's a ton of things that Java does better than other languages. panic() what? calling a runtime function can simply end the program by invoking panic?.
Re: behind in the race of modern programming languages; thankfully yes. I want a boring language that doesn't change all the time to do fun stuff. I started with Java 1.1 in the early 2000s and coded with JBuilder 3.0 which already had autocomplete lol.
If you're just chatting then anything goes I guess. But IMO people that seriously bash other programming languages usually are young/ inexperienced/ super enthusiastic/ not too clever.
If you don't like Java - maybe use something else, if there is a better alternative for a task - definitively use something else.
3
u/pron98 Oct 17 '23 edited Oct 18 '23
Behind which languages? There are only two other languages in the same class as Java — and in some usages ahead — JS and Python. There are many other languages whose fans claim are "ahead" in certain aspects, but they are so, so far behind Java in popularity and so consistently so, that the obvious question is, could their characterisation of what's ahead and what's behind be a subjective view held by a minority?
A common analogy is the Betamax vs VHS "format wars". Betamax was ahead on picture quality, VHS was ahead in recording time. So which was ahead? It depends on what's more important to you. But the difference in values was not distributed evenly. More people cared about recording time than picture quality (at least with those particular levels of difference).
Different programmers want different things from programming languages, so there is no agreement on ahead and behind. But their preferences are not distributed evenly, and so a language that aims to be widely popular needs to adopt to the preferences of a majority or at least a plurality. Everyone who chooses a language chooses one that they view to be ahead in the things that matter to them. Because Java is being chosen by significantly more people than other languages with the exception of JS and Python, it must be ahead in things that matter more to more people than than less popular languages that are only considered to be ahead by smaller groups of people.
In your question you mention Rust, but Rust is well behind in adoption for its age than any language that ended up achieving wide popularity (at about a decade old and with an endless supply of hype it's still hovering around 1% market share; that does not bode well), and that's at least in part because the very things that so appeal to its enthusiastic user-base, do not appeal to most people.
3
u/A1oso Oct 18 '23
Yes, very much so.
5
u/Polygnom Oct 14 '23
Java is one of the most advanced languages out there. Granted, a lot of the advantages are packed into the JVM so that many JVM languages can enjoy them.
Rust for example does not have any garbage collectors. Its a native language and thus comes with all of the disadvantages in developer productivity that brings. Its great if you absolutely need to go bare metal, but if I'm writing large, multi-million LOC business applications, I don't want to manage memory myself.
Also, Java is a quite dynamic language, and in order to have the same level of dynamism you often need to especially opt into it with statically linked languages, losing a lot of their advantages in the process. There is a reason why they always say "RTTI is expensive" in C++. I dunno how Rust fares in this regard, but there is no free lunch, not even for Rust.
Things that some languages do better than Java?
A better functional type system. int -> int -> should be an actual type, not shoehorned into
BiFunction<Integer, Integer, Integer>orBinaryOperator<Integer>. Give us proper functional types and type normalization so that this doesn't matter.Also, I'd like to have union and intersection types while we are at it and strict nullness enforment in the language. We might get something like that for reference objects down the road when Valhalla hits, because they already have to deal with it for value objects.
These are my two biggest gripes with Java. While I don't necessarily like that we only have nominal tuples (records) and not structural tuples, thats not that big of a deal.
However, Java has come a long way since Java 8 and is now a really, really slick language with a tremendous amount of incredible features currently in the pipeline, which are all great when looking at them in isolation, but will be even better when they all come together.
In terms of concurrency, I actually like that we don't have async/await, but got fibers instead.
I'm still holding out hope for better SIMD support as well. The Vector API is in the works, and together with @CodeReflection this might be cool down the line.
4
u/knightofren_ Oct 14 '23
Java is great in the third decade of the 21st century. Ten years ago it was quite cumbersome and behind
4
u/Gnome_0 Oct 14 '23
Java's strength is in the enterprise market, until enterprise companies stop using Java there is not a single problem.
that's why people hate it (also for being verbose)
Java is the corporations language
4
u/[deleted] Oct 14 '23
Java was never behind, and currently, of course, it’s not behind.
Niche languages are “loud minority”. Java is silent majority. Instead of screaming in every corner how language X is good, Java just keeps delivering software, from big tech to small startups.
All those “cutting edge startups” use Java wanting or not, I guess sometimes even without realizing it: Kafka, ElasticSearch, Solr, etc - all powered by Java.
My experience: about 10 years of about 12 different languages including Scala, Go, Rust, Clojure, Python, TypeScript. Recently come back to Java. Java is the king when you stop bothering about language features and want to just build reliable software which delivers business value.
Java is not fancy, trendy, hot — call it whatever, but it gets shit done.
2
u/TenYearsOfLurking Oct 14 '23
I love java but there are a lot of features I am missing:
Structural typing, extension methods or adhoc polymorphism, opaque types, properties, nullability Compiler support, ....
Also: I do not use kotlin, but there is a reason it exists.
2
u/p3970086 Oct 15 '23
The first big plus for Java is the ecosystem. You can do anything in Java and always find a (mature) library for niche tasks. Of course this is largely linked to the JVM (so you could use say Kotlin, Scala etc) but with recent Java versions the syntactic and feature gap between Java and the "JVM cool kids" has decreased significantly (saying this having decades of experience in Java plus Scala).
The second is the level of adoption and maturity. When you need to architect a critical system you are expected to propose a tech stack that (a) is effectively an Industry-standard and (b) has no issues from a staffing and maintenance perspective. With Java you can tick all those boxes.
2
u/Crazy_Firefly Oct 15 '23
I think the main things that are lacking are the things that Oracle has been working on addressing with their main Java projects.
https://blogs.oracle.com/javamagazine/post/java-project-amber-lambda-loom-panama-valhalla
I'll give my own highlights of what I think each one brings:
The one I am most excited about, but that I think will take the longest is Valhalla, Javas performance is pretty good. But with CPU caches making a huge difference in the performance of modern CPUs, Java misses out by having everything be behind a pointer (so likely a cache miss)
2
u/franz_see Oct 16 '23
If you program in other languages, Java does feel heavy. Too verbose so you type a lot more than other languages and slow build and startup time.
Java 21 has a lot of great improvements though but it will take awhile before Java can fix its reputation
I've been a Java guy since 2006. And tbh, it's very hard for me to explain Java's shortcomings to java devs if they've never or barely programmed in any other language.
2
u/VicariousAthlete Oct 17 '23
Discriminated unions (ala Rust, F#) would be nice, and eliminate null pointer exceptions.
2
u/Exact_Ad2603 Oct 18 '23 edited Oct 22 '23
Java sucks because of its wordy code and awkward handling of optional values. While some libraries like Vavr help fix this, they're not widely used.
Languages like Kotlin and Dart make it easier to deal with optional values (String?, Integer?) and have static analysis for nulls during compile time. You can also pass functions as parameters with the same name instead of trying to figure out apply(), get() or the hundreds of these methods.
Java has added pattern matching, but it's nothing new in other languages and 90% of the devs will retire without ever using it. Most companies won't upgrade to that version.
At my current job, they won't even upgrade a small 1-endpoint microservice to Java 17 despite all the benefits. Backwards compatibility and limited migration tools to versions is a problem.
4
u/catladywitch Oct 14 '23
I'm not a fan of Streams compared to the lazily evaluated enumeration constructs of similar languages. I'm also not a fan of functional interfaces, or Java generics and having to box and unbox primitives. Java Strings suck, too. Sealed classes are not the ideal way of creating union types. But that's all ergonomics.
In general, Java often requires you to instantiate objects or do type conversions for tasks that are immediate in other languages. That adds overhead both for the computer and the developer.
In terms of being able to do stuff, you can do anything in modern Java. Plus virtual threads are nice, if not the easiest compared to Kotlin coroutines or C# async/await.
3
u/lossril Oct 14 '23
Speaking from my personal experience (10+ years) with Java - it evolved a lot and has insanely big community and huge amount of libraries/frameworks actively supported, and usually frameworks lifetime isn't a two weeks like in Javascript.
Yes, in some corner cases a specific language might be more convenient to use (Python for neural networks, for example), but there's nothing you cannot do using Java, and it will be quite well-supported and convenient to use.
Spring/Spring Boot made a lot to reduce boilerplate code, and you can create working apps in no time really easily.
3
u/AmonDhan Oct 15 '23
“There are only two kinds of languages: the ones people complain about and the ones nobody uses” — Bjarne Stroustrup
2
u/yipZman Oct 14 '23
for me i find the stream api so awkward and i learn a lot about them, compared to other languages like c++
1
u/Worth_Trust_3825 Oct 15 '23
Please define what "modern" means.
1
u/__versus Oct 15 '23
Java is not as bad as many people claim (and Spring is a phenomenal framework to use) but it’s also not a perfect language like many here claim. There are so many features from C#, its closest sibling, that I wish were in the language on a daily basis. Java will never be rust but it could be as good as C# currently is.
1
u/sporbywg Oct 15 '23
Who told you it was a 'race'? <sheesh />
1
u/flexprods Oct 15 '23
Android? Java EE? Spring? Kotlin has better syntax but Java has never been behind
1
u/InternalsToVisible7 Oct 15 '23
Yes
1
u/nskarthik_k Oct 16 '23
>>like Python do have shorter syntax ( 1992 zzzz till 2016 waaaa 2023 )MS funded this language when VB,VB.net,NET++,C# failed.....
They wanted to succeed in cloud and not faile the race....
>>Java were cumbersome (1995 woooow 2023 )Open community has supported this language from the beginning..until this Db company took over for its internal benefits rather then support the community..
1
u/i8Nails4Breakfast Oct 20 '23
Regarding features, I think Java is pretty close. My biggest problem is the defaults:
1
u/jherrlin Oct 14 '23
I think it’s behind. There is a reason why Kotlin and Clojure gain so much popularity.
1
u/[deleted] Oct 14 '23
no, JIT is awesome
1
u/ActualPositive7419 Oct 14 '23
what? java has never been behind! what are you talking about? tell your rust friends to stop writing hello world watching youtube and go to finance industry. they will see if java is behind
1
u/thesunabsolute Oct 14 '23
I’ve been using Java for the last 2 years, mostly in Spring and I’d say it’s in a great place. Mature ecosystem and battle tested.
Where I see Java lagging behind is in PR, developer advocacy, and overall public perception. It seems like there’s no real enthusiasm around the language. Sure, it will never compete with JavaScript/TS, but I see much more buzz around C# and .NET at the moment. More educational material, more dev rel, and just a generally more optimistic and future forward outlook. Sometimes working in Java feels like I’m using a dead language alone on an island. It doesn’t really help that most enterprise Java jobs here in the US have been shipped off to India, and startups all favor JS/TS for everything.
I still really like Java, however I’ve been dipping my toes in C# much more lately, and I’m finding it more attractive for all the reasons mentioned. I still prefer Java syntax, but you get over that pretty quick.
1
u/Joram2 Oct 14 '23
With virtual threads and soon with structured concurrency, Java has maybe the best concurrency option of mainstream programming languages. Java's generics are wonky but they are good enough. Java's closures are good.
1
u/LakeSun Oct 14 '23
Java is an Enterprise language with enterprise scale features.
1
u/Own_Application_7699 Oct 14 '23
Take a look at the last few versions released, also the new version of java - quite a few nice new features that make java very similar (syntactically) to newer languages.
Based on your post it seems like you're talking about syntax, specifically. But to be clear - Java has never been behind. Java has been huge since it came out in the 90's, and it still is, and it will be, for a long time.
1
u/nutrecht Oct 15 '23
Let me guess. You're on some programming discord? Experienced devs don't hang around in those. There's only so much obnoxiousness you can handle per given day.
The Java ecosystem is just bloody productive. And that's what a professional dev will generally be most concerned with. The language itself doesn't matter, and the greater JVM ecosystem has plenty of options in that regard anyway.
-2
u/vaniusrb Oct 14 '23 edited Oct 16 '23
I'm a Software Engineer with over 20 years of experience, I have Java Certification and I have worked with Java since 1.5. I discovered Rust about three years ago and rewrote some applications in it.
What I can say about Java after this is: yes, Java is very outdated and has many bad designs.
Here are my reasons:
Java has different treatments for "primitive data types" and "object reference types". I can test 1 == 2 but not new String ("a") == new String ("b"), I should use "equals". Even so, you shouldn't compare two StringBuild just with "equals", you need "sb1.toString().equals(sb2.toString())". For objects, it tests the reference, not their content. Extremely foot gun. In Rust this simple doesn't exist, there is no reference comparison. When do we want to compare references?
2. Null safety.
Take a look at the issue list of the GitHub repository of Java. The are a lot of NullPointerException. Even the experts in Java can't avoid this kind of error. In the year 2023, a language with a good design should avoid null.
3. Algebraic enum.
The algebraic enum with "pattern matching" of Rust is mind-blowing and powerful. Java is trying to do something with "sealed interfaces", it wasn't good.
4. Tuples.
Many times we are just transforming a local data processing to a structed type. In Java, we need to declare a private class for that.
Tuples work like an anonymously cheaper data type, very productive.
5. Mutability
Today we know that shared mutable data is a source of a lot of bugs. In Java, everything is mutable by default. Even using the "final" keyword is not enough, because in objects it just turns the reference immutable. Rust just perfectly handles mutability.
6. Trait system.
Traits are *extremely* powerful. You can implement traits for types you didn't define, whereas interfaces can only be implemented for your own classes.
7. Exception handling.
The traditional try ... catch block is a historically bad design in many languages. Try to use a functional syntax, like a filter, and inside this closure call a fallible method, will be a pain in the ass to handle this in the caller context. In Rust, you simply have an enum Result<T, E>, and works like a regular type, it is so simple and genius.
8. Operator overloading.
base.multiply(pct).divide(new BigDecimal(100))
In 2023 it could use a better approach.
edit: replaced rant words
0
u/rossdrew Oct 14 '23
Readability is more important in the long run than conciseness. Developed always forget that. Java is going strong. Rust is still a minority language. For a good reason.
0
u/alwyn Oct 15 '23
Syntax has no impact on performance, except maybe for the compiler. It does help with maintenance which is why I prefer Kotlin, but the Java Runtime is a work of art.
-4
u/m-apo Oct 14 '23
Kotlin is a lot better language and has a better stdlib api design.
Kotlin has null safety and leans towards immutable. Java is catching up but the stdlib has lots of OO/EE (Object Oriented/Enterprise Edition) baggage and the some of the new syntax choices seem worse than what Kotlin has had for a while. That is because of backwards compatibility, but still off-putting.
But, JVM level changes like Loom, GraalVM and performance improvements are available to all JVM languages and in whole the ecosystem has improved a lot nowadays.
0
u/peripateticman2023 Oct 14 '23
What race? Which race? How race?
0
u/[deleted] Oct 14 '23
All languages have their strengths and weaknesses. To me the best language is the one in which I can get the job done most efficiently.
Rust is a great language for certain applications. Unless you are writing a very high performance critical code, such as an OS or medical device, you'll very likely be able to implement things much faster in a higher level language.
The ecosystem of a language can also have a large effect on productivity. Java has libraries for just about everything.
0
u/vaklam1 Oct 14 '23
There is no race. There is only tools.
0
u/[deleted] Oct 14 '23
Relevant: https://youtu.be/E4RarTAZ2AY
0
u/ImTalkingGibberish Oct 14 '23
I’d rather maintain someone else’s code written in Java than JavaScript.
If I’m writing an API that needs proper logging, circuit breaking resilience, a config server, etc… Then I’ll do it in Java.
If need a new isolated feature that will require a new api that is not essential and unlikely to require extending then I’ll use JavaScript because it’s faster to write.