Java has its issues. Its specification stagnated for a number of years due to the sun collapse and oracle acquisition. It also does not show its strengths in command line utilities, or in GUIs(Swing enthusiasts, fight me.), or in games. It really only shines when running longer lived server side applications where the tradeoffs the language makes are stronger. When you do use it for application development it is often mired in legacy framework baggage that adds little while causing you headaches.
Once application servers are killed off for good, and the next LTS JDK releases, the future should be much more exciting.
JVM startup time is way faster in newer versions. I saw a benchmark in Java 15 where the JVM fired up faster than Python on average (<50ms). Java command line utilities with modern CLI frameworks like PicoCLI are fast and easy to work with.
Java also has the only good cross-platform Desktop UI outside of QT. Unless you want to write C++ or use janky QT binders for other languages, Java is still the king of Desktop UI's. Java's new cross-platform packaging tool is awesome and JavaFX ain't bad either.
Java's UI is relatively fast because it uses native widgets. Compare that to something like Electron where performance is horrific. Java also uses less memory than JS or Python so if you want a decently performant Desktop UI, Java is usually the best choice.
You probably use a ton of Java Desktop UI's without even realizing it because they look native and everyone packages stripped versions of the JVM with their app these days.
The startup times most likely rely on using jlink to build a custom jvm. This is still a relatively new feature and is a perfect example of a place java stagnated for years on! With the next LTS this should be used much more often.
Java's ui, as you put it, does not use native widgets. Swing is notorious for looking the same across almost all applications. I can't speak much towards java fx other than to say it's popularity has never really been high.
Swing uses AWT underneath and some widgets are truly native, but you are right that many components aren't. I didn't know this. Swing's native look and feel is dead-on these days. I usually can't tell the difference at least on Windows. Swing looks like hell with the default look and feel and lazy devs don't bother switching it.
The startup times I'm talking about are for console apps using plain OpenJDK with AppCDS enabled. Check out the massive startup time (and memory) improvements in newer JDK's https://cl4es.github.io/2020/12/06/Towards-OpenJDK-17.html
Java 16 starts in barely over 20ms for simple apps. This is basically fast as interpreted scripting languages like Python
The one benefit of electron is the decimation of a preference on “native widgets”. Nowadays it is much more acceptable to have a slightly different looking window, which while many would say is not a positive thing, it does help Java’s case. Hopefully we can see more growth in this area.
And JavaFX is a hidden gem. I’m not sure why is it not more popular, I think it is far the most productive GUI framework. And with Valhalla, I think it will get a decent boost in performance (for 2D games, it churns on small “primitive” objects quite a bit)
[Java] also does not show its strengths in ... games.
i wonder if that's set to change with max 0.5ms and average 0.05ms gc pauses for zgc and performance improvements from project valhalla primitive classes and generic specialization
Hard to say. Garbage collectors are tricky beasts and while valhalla types should help certain scenarios they don't seem to solve the larger issue of needing to be able to better manage your memory. Then again I don't do game dev so this is just my opinion!
While ZGC is better about not pausing the world its not guaranteed to always improve performance. For example, if you are capping out your CPU ZGC may be unable to execute properly and may need to stop the world for longer and longer. As with any garbage collector you need to load test and see how it performs.
It isn't just game dev. High performance Java generally looks little like the usual enterprisey stuff. It's a little sad that the prevailing image of Java and its problem space is so much "enterprise web app" when it's a much more flexible language than that.
That is because enterprise web apps is where Java really shines in comparison to alternatives. This is partly a language feature, partly due to the servlet specification being a really well thought out platform for web applications, combined with a suite of libraries useful in business situations. You can have the worst developers in the world contribute to the application and it will mostly plod on without too many issues.
Java is definitely useful elsewhere but almost no other language provides so much for this particular use case.
Hardly. If Java had ZGC and project Valhalla 5-10 years ago it would have the potential to become dominant in game dev. But nowadays Unity, the most popular engine, uses C# for scripting. Unity certainly wont just switch to Java, they invested a ton of time making C# scripting as performant as possible and all of their users are familiar with C# not only as a language but also all the tooling related to it.
Of course, new game engine could come out, but that would take years to gain any traction, and by that time, other popular engines will already be more mature and have way more available resources and developers. I mean if you look at the gamedev world now, everyone is either using Unity, MonoGame, Unreal or writing their own engine from scratch in C++. There are tons of other engines popping up every now and then, but they are mostly used by a small number of enthusiasts or people who just like to experiment.
I would imagine that today GC is no longer an issue, with G1GC. I don't think ZGC will matter so much, because there's just a limit to how much GC needs to improve before it stops being a problem.
Back when I was learning Java, sometime in java 7 time, I was working on a realtime simulator software that caused a steady 50 % CPU load on my then-laptop, and a new video frame was required 50 times per second. For that target, the old CMS collector was manageable if you kept the heap size small, as the collection time generally grew roughly linearly in proportion of the size of heap to collect with the older algorithms. Thus smaller heap meant more frequent but shorter pauses -- technically you spend more time doing GC in total, but latency will have a bound that is better suited for a realtime application. (Of course, such statement is subject to the rate garbage gets generated, and so on, as you can increase GC load without bound just by generating more garbage.)
I never did measure how big an impact the GC had, though, I just observed if underruns ever happened, and found that with small heaps they ceased to happen. Margin of error was within factor of 2 to 3, e.g. 128 MB heap was fine, but 512 MB heap was not, and so I kept the heap at 128 MB. My guess is that collection times were probably always less than some 4 ms, not enough to cause underruns.
I don't really get why you would use jbang for anything. If I am producing a runnable application I can produce an executable jar already. I just don't understand what the benefit is to it instead of using an existing build tool.
As I understand graalvm still is not compatible with everything. It also doesn't really seem popular with real world developers even though it's being pushed everywhere on reddit. Probably because none of us can use it with any of our existing applications due to said incompatibilities. For example spring is still incompatible.
if you are fine using maven/gradle and whatever keep using it - jbang can still be used to run that output without user having to install and setup java.
if you are fine with the ceremony of dealing with multiple artifacts and multi nested directories just to write a utility keep doing that - jbang lets you just have one file (like bash, python,etc.) and use that directly - no separate build/compile step.
if you love to deal with maven/gradle requirements to do a few things in a project then do that - jbang lets you just write a .java file and run it any kind of project and be used as a debuggable and portable set of utilities not tied to specific build system.
If you don't use a big framework avoiding reflection is not too hard. I think they are really pushing to minimize it for graal features to work properly.
Java's runtime reflection is really fast. Simple calls are generally over half "native" speed of grabbing the field or calling the method statically. Most languages with runtime reflection the performance is shit. Java's implementation is quite good.
Its specification stagnated for a number of years due to the sun collapse and oracle acquisition.
I disagree, a lot of that was the best part of Java. Started with 8 it started to gey bloated and the most recent stuff is a huge inconsistent nightmare. Java was best when it stayed stayed simple rather than becoming a dumping ground for 3 or more different buzzword programming ideologies.
54
u/deadron Apr 20 '21
Java has its issues. Its specification stagnated for a number of years due to the sun collapse and oracle acquisition. It also does not show its strengths in command line utilities, or in GUIs(Swing enthusiasts, fight me.), or in games. It really only shines when running longer lived server side applications where the tradeoffs the language makes are stronger. When you do use it for application development it is often mired in legacy framework baggage that adds little while causing you headaches.
Once application servers are killed off for good, and the next LTS JDK releases, the future should be much more exciting.