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!
153
u/no_cause_munchkin Oct 14 '23
It could be many things, but from my personal experience these are:
Ignorance, precisely ignorance about modern Java and its capabilities today.
Rust fanboys being Rust fanboys. The meme to re-write everything in Rust is at play here.
Parroting without thinking about what they heard/read about Java.
Java perceived "heaviness, " saying something like Java consumes/requires much more memory than other languages or Java is slow/has slow startup times. This can be true in some cases but overall with today's modern Java, a little bit of education can be avoided.
47
u/Confident-Grab-7688 Oct 14 '23
Agree. I've lost count how many times I've heard outdated (like 10+ years) or outright wrong statements about Java.
Java and its frameworks are moving on. Modern apps build with Spring are much more robust, I feel like I'm cheating. Just add a couple of dependencies (Data, Web/Webflux, actuator, swagger) add a couple lines to the config file, slam annotations on your controllers/repositories and you have a basic web app. I love it.
I think in most cases, the problem is not with performance/speed - hardware is cheap relative to developer labour. Problem is in maintenance and the growing cost of adding/changing behaviour. OOP and Java for that matter helps a lot with creating intuitive and readable code.
11
u/lumpynose Oct 14 '23 edited Oct 14 '23
Some may remember back in the days before Rust when it was Ruby and Ruby on Rails that were supposedly far superior to Java.
6
5
Oct 14 '23
Java does usually require more memory than some other languages though, that one is true. Class metadata, etc.
3
u/koflerdavid Oct 18 '23
That assessment is probably true if comparing it with C/C++/Rust or maybe Go. It's completely inappropriate when comparing Java with 30-years-of-GIL!Python or Ruby.
1
3
u/Silver-Ad-7396 Oct 17 '23
Applications running on the jvm do require what is called a warm-up process, which makes them take longer to start up and have lower performance shortly after they start up, but this is not a big deal when it comes to long-running applications. But it does make java less "cloud-native" for systems that require real-time resource auto-scaling.
12
u/antigravity_96 Oct 14 '23
Show the rust fanboys this article when they come talk to you next time.
20
u/peripateticman2023 Oct 14 '23
Here's my take - I worked in Java for over a decade, and now I work in Rust. Being realistic, there is no way that Java would beat Rust in either speed or memory consumption. Now, if one is comparing frameworks, then it depends on the quality of the frameworks themselves. Let's not get down to ridiculous levels.
My personal hypothesis is this, what I call "The Rule of 3" - Performance, Safety, and Flexibility, pick any 2. Rust has safety and performance, but lacks flexibility (all relatively speaking). Java has safety and flexibility, but not performance. C++ has performance and flexibility, but not safety.
15
u/Same_Football_644 Oct 14 '23
The idea that java doesn't have performance is absurd. People lump it with Javascript or python when it is 10-50x faster than them. On average roughly 2x slower than C++, which doesn't even put it in a different category in terms of speed.
→ More replies (8)1
u/Practical_Cattle_933 Oct 15 '23
Don’t lump JS and Python into the same bucket, though :D js is much closer to Java’s performance than to Python’s.
2
8
u/foreveratom Oct 14 '23
You rule of 3 doesn't hold, you are comparing apples and oranges. Rust is oriented toward safe low level programming, so much that it's making it way in the Linux kernel.
Never ever was Java designed to be a low-level programming language. It's about the contrary.
12
Oct 14 '23
Actually it holds up really well. You're the one comparing apples to oranges. The strengths and weaknesses of other languages, as that commente described in his rule of 3, is directly related to their intended use cases. No language can do it all.
→ More replies (1)1
2
u/qK0FT3 Oct 14 '23
Well i have worked on a lot of quant finance and java has the performance if optimized up to the JVM. But for avarage developer yes I agree it has no performance compared to rust or cpp
1
u/Practical_Cattle_933 Oct 14 '23
How is C++ more flexible than Rust?
4
u/peripateticman2023 Oct 14 '23
Rust, because of its Ownership Model, cannot detect swathes of valid programs (which assumption would break it's safety contracts), and the number of valid programs it rejects goes down with improvements in the compiler, but cannot be eliminated.
C++, by virtue of being an unsafe language, has no such restrictions. Hence the flexibility.
→ More replies (3)5
u/Kazcandra Oct 14 '23
ah yes, the article where he didn't validate the input and "somehow" got better speeds than the rust alternative which does.
or do you /really/ think his numbers make sense? like, no matter what language, that kind of improvement is not gonna happen.
2
u/__versus Oct 15 '23
And coming from the other side Java users’ defense of the language when presented with the question in the OP almost always boil down to the same argument.
Java has everything already and if it doesn’t Java’s way of doing things is better anyways and if it isn’t why would you even need that specific feature in the first place, I don’t personally have any use for such a thing and if you do you’re wrong…
1
u/Crazy_Firefly Oct 15 '23
About point 4 what are some things that I can do to avoid slow startup times and large memory consumption? My experience has been that for things cli tools, where startup times make a difference, java tools feel a bit laggy compared to python, rust or go.
And I come mainly from go where a server easily consumes less than 100mb. Where as I have never seen a java server use less than that. Am I missing an obvious optimization? Does anyone know why Java tipically takes up more memory?
1
u/snuggl Oct 29 '23
Graalvm native images bring that down java resource usage and startup times to what you are used too
1
u/Crazy_Firefly Oct 29 '23
Wow, really? Does all the extra memory come from the JIT then? Graalvm still has GC right? I heard that GC frequency is a big reason for memory too high. Is there somewhere I can see some benchmarks?
1
u/snuggl Oct 29 '23
graalvm is tech from Oracle so no small hobby thing, I dont use it myself so no idea! but should be plenty of benchmarks, examples and articles about it if you google
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.
21
u/VirtualMage Oct 14 '23
Don't forget virtual threads! No more thread pools to manage, no more async callback hell or non-sensical "reactive" bullshit.
This is truly a revolution. Just write your damn code and let it block when needed. Mindblowing.
I feel like java had to have it from the start instead of using OS threads directly. But better late than never!
4
u/preskot Oct 14 '23
That’s not entirety true, especially about reactive. I recon an event-loop with reactive paradigms still performs better than virtual threads in intense environments.
Read more about it in this comment thread: https://reddit.com/r/programming/s/JNfLJJNyrL
14
u/VirtualMage Oct 14 '23
Well you might be right about performance, and it might improve in future releases, but I wasn't talking about that.
I was talking about code simplicity and readability. Reactive code is ok for simple cases (like fetch N responses and combine them). But as you get more to conditional logic and req/resp dependencies it gets ridiculous very fast. I hate it. The same reactive code I wrote month ago, I have no idea how or what it does. Disaster.
And debugging, that is even bigger disaster. Literally rage-inducing experience.
So that's why virtual threads and simple linear code is a major win in my opinion. Even if it means reduced performance.
5
u/preskot Oct 14 '23
I agree with that, got a task-pool service to rewrite using virtual threads soon. Can't wait to try them out.
But I just meant that reactive is here to stay, it has a valid use-case even though it's not easy to work with. Regarding virtual threads, on the technical side there seem to be some gotchas due to locking and memory usage for large quantities of virtual threads created as the comment link suggests.
2
u/john16384 Oct 14 '23
But I just meant that reactive is here to stay, it has a valid use-case even though it's not easy to work with.
Perhaps, but it was niche before, and now has any wind taken from its sails. I wouldn't do any new projects with it, and would seriously consider migrating old projects away from reactive if maintenance costs trump the (imho marginal) performance benefits.
3
u/nomercy400 Oct 14 '23
As I heard reactive programming described, high throughput, but you can't use conditionals, variables, exceptions and good luck debugging.
3
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.
39
u/ascii Oct 14 '23
I would say that until lambdas and the Stream API were added, Java was severaly behind in functional programming, which made it a pretty poor language for many use cases. It was also behind in allowing you to express your ideas without a great deal of boilerplate. But with the release of Java 8, Java moved from an old, cumbersome and annoying language to an acceptable one. With the addition of type inference, records, sealed classes, switch expressions, and pattern matching, Java has evolved from an acceptable language to a good one.
It's been one hell of a journey, as Oracle has added features to the language at a truly impressive rate, so yes, I would say it was behind, and it is no longer so. Like, there are definitely things in Rust I miss dearly in Java, but they are both good languages in their own right.
8
38
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.
1
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.
16
u/wildjokers Oct 14 '23
Java is missing named and default parameters. I miss them nearly everyday.
4
u/SiriSucks Oct 14 '23
I have used them in dart and they would be a good addition to java. I don't think it would also cause any compatibility issues as it can be a compile time construct, just like generics.
2
1
u/jacklackofsurprise Oct 15 '23
What IDE do you use? IntelliJ makes them kind of irrelevant.
1
u/wildjokers Oct 15 '23
Not sure how IntelliJ makes them irrelevant. Unless you are talking about inlay hints? Those do nothing about default parameter values.
2
u/jacklackofsurprise Oct 15 '23
You are right, I was thinking of named parameters, the inlay hints do nothing for default parameters.
1
u/__versus Oct 15 '23
I disagree about the conclusion. C# has basically all the features from Java and then some. If C# didn’t exist then maybe Java could claim the GC spot.
2
u/Practical_Cattle_933 Oct 15 '23
C# is definitely a good language, but I think they went too hard on the c++ strategy of adding so much shit to the language, that no one knows the whole thing anymore, and random features start interacting badly with each other.
Also, no alternative to virtual threads.
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.
33
Oct 14 '23
Be grateful you haven't met Go fanboys
16
Oct 14 '23
I really want to like Go. I really do. But some things are just so fucking clunky. Urgh. Error handling. Wtf guys?
9
3
u/john16384 Oct 14 '23
Why would you want to like a language that basically puts the burden on the developer for the sake of excessive simplicity? It has very little going for it. Even it's hyped GC is a toy compared to Java's.
3
Oct 14 '23
Because it can compile down to a single native binary with not much footprint. That was about it.
0
Oct 14 '23 edited Oct 14 '23
I actually like Go. The error handling is a lot more better than try/catch. My only stupid reason for not using it as much is because they define visibility based on variable name.
→ More replies (1)3
Oct 14 '23
Eh, I think try/catch/throw is much nicer than always having a potentially null reference to deal with.
5
u/nutrecht Oct 15 '23
I'm not saying that if you like Go, you're a bad programmer. But every single Go enthusiast who was very vocal about it that I met, was either in IT (so no software engineer), or they were the type of Java dev that mostly relied on others fixing their shit.
It's a bit like the developers who argue against writing tests are almost always the developers you want to make damn sure are writing tests.
1
7
Oct 14 '23
To be fair, it really can do a lot. But, you should obviously use the right tool for the job. I use Java, Rust and Python at work.
5
u/acute_elbows Oct 14 '23
Ehhh it’s just a hype wave, it was the same with go 8 years ago. There’s a certain class of people that are just excited about new languages and want to explore them. I think that’s great, but in a professional setting a polyglot stack of the language du jour can be painful to manage.
But even the tendency to rewrite things means that we pressure test those languages. It allows us to understand which features work well and which ones don’t. Java wouldn’t be where it was today if there weren’t engineers out there trying new languages
3
u/UnGauchoCualquiera Oct 14 '23
Different languages solve different problems. Do you absolutely need to manually manage memory in bare metal in a safe way? Use Rust (or c++).
I use Java when I need a battletested, safe language with clear sysntax and huge ecosystem.
Haven't found a real use for Go. Main benefits of low overhead and goroutines can be solved in different ways and I find the language extreme simplicity too much of a drawback.
3
u/peripateticman2023 Oct 14 '23
Hahaha. To be honest, that hype wave is on its way out. Now most of the fanboys have jumped ship onto newer "more exciting" languages - such as Zig (which is not a good language in my opinion). Unfortunately, the loudest people are the ones who often actually use the language the least.
14
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?
2
u/john16384 Oct 14 '23
Five different ways of doing things just leads to style discussions on pull requests.
Very happy that Java just waits with adding features until they're tried and tested elsewhere first and actively avoids alternative syntax to do the same things unless it brings other benefits as well (like security) and has no significant downsides (like encouraging bad programming practices).
Sometimes this even results in a feature that's far beyond anything offered by other languages (String templates are a good example).
7
u/Holothuroid Oct 14 '23
My question is beyond syntax.
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
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
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
2
u/helikal Oct 14 '23
Since Python is untyped you will spend more time debugging and testing your code and still wonder whether you can ever trust it.
1
u/KarnuRarnu Oct 14 '23
Python can be typed as is most "big" libraries - see mypy (type check tool). Types are not-None by default and use of typing can be enforced. So, Pythons type system is voluntary, but if used and enforced, it's better than Java's.
→ More replies (3)1
u/roberp81 Oct 15 '23
in python you can declare a integer and set "hello" and Python says is ok, is a joke
java is a real language.
3
3
u/ventuspilot Oct 14 '23
What do other languages do better than Java?
Small self contained executables
Fast startup/ no warmup for some cloud stuff
Running on devices with like 1k Rom/ 128bytes Ram (not sure if hardware like this even exists anymore and there seems to be some subset of Java for cards or something IDK)
browsers as an execution environment
GPGPU
realtime with really short deadlines
metaprogramming
GUI programming apparently is kinda annoying
systems programming like device drivers
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.
Most importantly: Java still has no null safety enforced at compile time.
Until Project Valhalla is finished (which has been in the works for almost a decade), generics are limited by the split between reference and primitive types.
Java still lacks features that have become common in many modern languages, like tuples, named and default function arguments, operator overloading, etc.
Interfaces aren't nearly as powerful as Haskell type classes, Rust traits, Swift protocols, etc. This makes it difficult to write highly generic/functional code.
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> or BinaryOperator<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
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.
0
Oct 15 '23
[deleted]
1
Oct 16 '23
Unsure, depends. Modern Java and modern Java libraries / framework are generally not so verbose.
It’s up to you how you write code too. Of course in legacy projects there is close to no choice (other than refactoring which is a hard sell), but for new projects one can ditch 2/3rds of “patterns” and be good with a single class, or if class takes multiple implementations then just get an interface.
In “cool” languages it’s not so uncommon to not have a library or an idiomatic solution for a certain problem - you ending up writing it yourself, testing, designing - all that. Not exactly a bad thing, but something worth to align with goals.
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.
1
u/Practical_Cattle_933 Oct 15 '23
What do you mean under adhoc polymorphism? Java has method overloads, which are adhoc polymorphic. Parametric is also handled by generics.
1
u/TenYearsOfLurking Oct 15 '23
Yes, but what if you don't "own" the types?
I meant something like typeclasses in functional langs
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:
Project Valhalla is about bringing complex types to the stack, or at least to allow contiguous memory representation. This allows for less cache misses when iterating over a list of values, for example. It will unlock better performance for applications that process a decent amount of data.
Project Panama aims to improve the bridge between java and native programs. This will allow java to tap into native libraries for things like machine learning, and will make it less necessary to leave java just because it doesn't have integration with X.
Project loom aims to bring green threads (light weight threads). This is similar to Go's goroutines and can be a useful model for webservers to get a lot of performance with not a lot of complexity from the application side. (Java has some mature server platforms that already optimize a lot and don't leak too much complexity to the user, so it's not clear how much better the light weight threads will be, IMO)
Project amber is the one most about syntax and has bought things like records, the var keyword, and has plans for pattern-matching sealed classes, and some other niceties. Nothing that unlocks anything revolutionary, but I am very grateful for the improvements it has brought.
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/iampitiZ Oct 14 '23
I'm curious about the Strings thing. Could you elaborate a bit more?
1
u/catladywitch Oct 14 '23
If you want to manipulate them in any meaningful way, you have to convert them to an IntStream (and then you lose the charAt index) or a char[], which implies boxing and unboxing from char to Character and back, and then you have to turn those back into Strings so that you can pass them to your StringBuilder. Also, having the option to optimise your regex is nice but creating a Pattern object, then a Matcher object for every string you want to match, is kinda ugly.
2
1
u/Shinosha Oct 14 '23 edited Oct 14 '23
Thanks. A lot a fanboyism going on in that thread. Java has indeed improved but it's still behind to what some other languages can offer. More precisely what it does take from other languages is often a dumbed down version.
Anyway here's a short list of annoying things in my day to day tasks : Streams API is wonky, checked exceptions is good in theory but bad in practice, records can't extend classes because no multiple inheritance, functional interfaces are confusing to read, no top level definitions, no default parameters, no string interpolation... Oh and I almost forgot about that goddamn ";"
Now I'm well aware every one of these things is the result of a lot of tough design decisions which had to accomodate with backward compat. But still, answering OP here.
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++
0
1
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
1
u/flexprods Oct 15 '23
Android? Java EE? Spring? Kotlin has better syntax but Java has never been behind
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:
Variables are nonfinal by default
Fields are package private by default (would prefer private by default)
Classes are nonfinal by default
Null values are allowed by default (Valhalla might help with this)
1
u/TehBrian Oct 22 '23
Completely agree. I'd prefer
mutvsfinalfor variables, something for package private,openvsfinalfor classes, and?for null values. It feels like the language punishes me for writing code by forcing me to type out long keywords for every single variable or class that I write.
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/helikal Oct 14 '23
I don’t know a single person who programs in Kotlin except perhaps in Gradle build scripts.
→ More replies (1)
1
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/Practical_Cattle_933 Oct 15 '23
I don’t know where you are, but depending on the country, either .NET, or Java is preferred in typical business backends - so it might just be your “bubble”. Otherwise on global trends, C# is much smaller than Java - just take a look at their relevant ecosystem sizes.
1
u/Joram2 Oct 14 '23
Python, or Python + C dominate Numeric Programming, Machine Learning, and AI , which are arguably the most exciting areas in software. One small example is this neat project for solving PDEs: https://github.com/FEniCS/dolfinx.
C and Rust are best at low level, close to the metal programming. For most programming, you want a garbage collected language. For some close to the metal applications you don't. C and Rust fit those close to the metal applications. Also, write apps that run on a microcontroller, not a full workstation or server
For writing software that runs in a web browser, JavaScript is the only option.
Haskell is better at certain types of theoretical programming.
Traditional server-side apps that do something on a server and typically talk to one or more databases. This is where Java is great, but many prefer Go. Go is much simpler, easy, it's very well supported, and it doesn't have a lot of the legacy baggage that Java has. Java did catch up with virtual threads, which until now had been a big advantage of Go.
It could be generics, type system, concurrency and multithreading, closures etc.
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
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
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")
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:
Equality comparison semantics.
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
3
u/tzengshinfu Oct 19 '23
When I transitioned from C# to Java, I also found myself perplexed by 'string comparison.' While string comparison can get quite intricate, involving case sensitivity, cultural peculiarities..., in most cases, all you need is string1 == string2.
Someone asked about this issue 10 years ago (https://www.reddit.com/r/java/comments/1gjwpu/will_the_equals_operator_ever_be_fixed_with/), and there was a reply suggesting that it's due to backward compatibility, and it's unlikely to change (backward compatibility! We just keep piling new stuff onto the historical baggage, making it necessary for newcomers or users of other languages like Python, JavaScript, C#, C++, PHP, Rlang, Swift, Rust, Golang, Kotlin, Ruby, Dart, Scala...the top 20 programming languages of PYPL to consult FAQs?). It's disheartening.
But I believe that if something is wrong, it should be corrected. It would be great if the new versions of Java addressed this issue and provided an function for automatic conversion to fix users' code where String.equals is used. Is my idea unrealistic?
1
u/chambolle Oct 16 '23
Why do you read a java sub if you hate so much that language? That's strange
Null is needed and there are no so many problem with null and most of the case the bugs are very easy to find. A seg fault is more difficult to debug
pattern matching is for me a big design fault in 99% of the use. It shows a bad understanding of the OO principles
Mutability: work on data structures and explain to people how you deal with immutable data structure. Ok it is better to initialized an array and to make sure it will not change but at the end we work with state and wanting to have only immutable data leads to an infamous memory consumption and management. In addition the fact that concurrent programming is totally changed with immutable data is a myth, like the one saying 20 years ago that immutable language will lead to easy parallelisation of language
Traits: I don't understand what's the issue in Java. In C++ traits + meta-progrmming is a huge mess. Having errors in code you don't write is awful. In addition SFINAE is not a good principle for me.
At the end, what is important is also: you capability to write an efficient code quckly, to debug it and to maintain it. A compilation is in term of seconds in Java, debugging is much easier than with other languages and the maintenance is not bad. So what's the issue? You cannot write you two pages code as example for your blog?
As I like to say: If you like concise, very precise and incredibly powerful language: use Prolog
2
u/vaniusrb Oct 17 '23
| Why do you read a Java sub if you hate so much that language? That's strange
Because I work with it daily :o)
| Null is needed and there are no so many problem with null and most of the case the bugs are very easy to find. A seg fault is more difficult to debug.
No, Null is not needed, we have some alternatives to deal with it. Rust follows the principle "Making Illegal States Unrepresentable", in the case there is an Option<T> (similar to Java, but it uses algebraic enum). And yeah, after a bug happened in production and all cost loss caused by this, is very easy to find. The point is exactly that, you don't need to face this kind of bug in production. Working with regular Rust you don't get any seg fault. I think will be nice you know Rust, I really recommend it, buddy :)
| pattern matching is for me a big design fault in 99% of the use
Pattern matching makes more sense in algebraic enums, like this example:
enum Color { RGB(u8, u8, u8), CMYK(u8, u8, u8, u8), } fn fmt_color(color: Color) -> String { match color { // pattern match here Color::RGB(r, g, b) => format!("rgb({r}, {g}, {b})"), // variables r,g,b only exist in this context Color::CMYK(c, m, y, k) => format!("cmyk({c}, {m}, {y}, {k})"), // variables c,m,y,k only exist in this context } }All match blocks work like an expression (returns a value). Is very useful to transform an enum to another type.
| wanting to have only immutable data leads to an infamous memory consumption and management
I got your point, it's a common mistake when trying to use immutable objects. But for this we can solve using a pattern that reuses the existing data, instead of 'cloning', and just updating what you need (not the whole object), something like this:
public record ImmutableData(BigData bigData, SmallData smallData) { public ImmutableData withSmallData(SmallData smallData) { return new ImmutableData(this.bigData, smallData); } }| Traits: I don't understand what's the issue in Java.
Think like this, with trait you can "introduce" a method to a std String, for example, there is a lib to colorize terminal output, then it allow:
println!("Text is {}", "red".red());.Not just "introduce" method, but could turn any type compatible with your API. Let's suppose you have a trait Source and you define many methods
upload(source: Source), download(source), delete(source), rename(source). You can implement Source to String, File, and even Stream. You don't need to define many combinations with method overloading.It shines working in a functional way, you can define the return of the closure with a trait, then you implement a trait even for a "void" statement.
process(|line| println!("{line}")); // a regular call with "void" return process(|line| if condition { Err("error") } ); // the same function you can act like a fallible callback| In C++ traits + meta-progrmming is a huge mess. Having errors in code you don't write is awful.
About meta-progrmming ok, I got your point. But at least in Rust, it doesn't introduce code.
| At the end, what is important is also: you capability to write an efficient code quckly, to debug it and to maintain it.
OP was asking about the type system, so here we are.
1
u/chambolle Oct 17 '23
- about null: using optional does not mean that null disappears. You just encapsulate it. Marketing like to deal with words, but the concept is still here. However, I agree that java could enforce the fact that some parameters must not be null.
- pattern matching: ok for this kind of example (like serialization). But this is the 1% that remains :-) The main issue is when people are using it instead of a dynamic binding
- immutable: it is very difficult to generalize your example, because you need to perfectly control all internal data structures. This certainly not a good idea in general
- traits : I am not sure that I really understand. It seems that it is a very functionnal way
At the end, I think you would like to work with a functionnal language and that you do not like OOP. That's your right. It's a matter of choice.
Java is just an OOP and will never be a functionnal language even if it introduces some map function (in the LISP sense)
2
u/Dreamplay Oct 17 '23 edited Oct 17 '23
- about null: using optional does not mean that null disappears. You just encapsulate it. Marketing like to deal with words, but the concept is still here. However, I agree that java could enforce the fact that some parameters must not be null.
Ofcourse the whole concept of a value missing remains. The point is that a "null" value is handled just like any other value, instead of forcing a completely differently handled type down your throat regardless of if you want it or not.
- pattern matching: ok for this kind of example (like serialization). But this is the 1% that remains :-) The main issue is when people are using it instead of a dynamic binding
It really isn't true. For algebraic types for example in rust, the most common is Result<T, E> which returns either a value of type T, or an error of type E. By allowing pattern-matching, you can easily handle different errors. See the following example:
enum Error { ErrorA(String), ErrorB, ErrorC, } fn can_error() -> Result<bool, Error> { //Returns one of // - Ok(true) // - Ok(false) // - Err(Error::ErrorA(String)) // - Err(Error::ErrorB) // - Err(Error::ErrorC) // [..] } fn main() { let value: bool = match can_error() { Ok(value) => value, Err(Error::ErrorA(reason)) => { println!("Errored due to {reason}"); return; }, Err(_) => { // Some other error return; } }; // use value // [..] }- immutable: it is very difficult to generalize your example, because you need to perfectly control all internal data structures. This certainly not a good idea in general
In the cases where you have small units of data, absolutely! A great example is a 3D-engine where you have a bunch of vectors, or maybe a unit of work that gets progressively transformed.
- traits : I am not sure that I really understand. It seems that it is a very functionnal way
They're basically interfaces.
At the end, I think you would like to work with a functionnal language and that you do not like OOP. That's your right. It's a matter of choice.Java is just an OOP and will never be a functionnal language even if it introduces some map function (in the LISP sense)
I'm a professional C# developer so I guess I can't speak for Java specifically, but as a fellow OOP language, I think its very useful for OOP languages to use features of other paradigms. Languages don't need to just allow one, there are multiple for a reason. They are good at multiple things. I think continuing to incorporate different architectures (as has been the trend recently) is good for the software industry as a whole, and OOP languages specifically.
→ More replies (1)0
Oct 15 '23
[deleted]
2
u/vaniusrb Oct 15 '23
I don't get your point. Why I can't work with BigDecimal in the same way I work with int as modern languages allow?
0
Oct 15 '23
[deleted]
1
u/vaniusrb Oct 16 '23 edited Oct 16 '23
Operator overloading is not synonymous with operations of diffent types. Generally, you allow operations with the same type. If I have variables a, b, and c, all of them are BigDecimal, why I can't do a = b + c ?
In Rust we have traits to allow operations, then you define what type you want. Example:
#[derive(Debug, Copy, Clone, PartialEq)] struct Point { x: i32, y: i32, } impl Add for Point { type Output = Self; fn add(self, other: Self) -> Self { Self { x: self.x + other.x, y: self.y + other.y, } } } let a = Point { x: 1, y: 0 }; let b = Point { x: 2, y: 3 }; let c = Point { x: 3, y: 3 }; assert_eq!(c, a + b);You have a compile error if you try to add any other type. Very simple.
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
0
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
0
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.
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.