Hi, so I recently discovered the online MOOC.fi, the free java programming course, and have just started it. What struck me is the introduction said its a write once, run anywhere platform. And i’ve been following the first couple of topics just fine on my Linux laptop.
So how come it is never mentioned along with they likes of snaps and flatpaks and appimages etc? It seems to be something that works cross platform, are there fundamental issues with it that mean nobody makes desktop apps with java?
Don’t you still have to install a JRE (Java Runtime Environment) for java apps to work? This used to be one of the drawbacks to coding in java – “You can use my app, if you have this other program running.” Generally, the idea is that when a program is “compiled” it runs stand alone without the need for the RE. Maybe things have changed as i have not stayed up to date in this area.
I don’t know much about this free course you’ve mentioned. I hope you find it useful; I might look into it too.
I first used Java in the mid-late 90s when it was new and upcoming and have continued to use it as and when I code. The write-once-run-anywhere philosophy of Java did become a little muddied especially of late when Android and iOS gained popularity. One definite advantage for me though, is code I write on Linux will generally run without altering or recompiling on Windows (if I have to use Windows, which is rare).
The JRE (Java Runtime Environment) is needed to run compiled Java code, because Java targets a virtual machine for the compiled code to run on which is implemented in the JRE for a particular platform, with the JRE interfacing with native OS as needed.
Flatpaks, Snaps and AppImage run on the native Linux platform as far as I am aware, even if they’re in containers to some extent, so they’re a bit different in that respect. Just my thoughts
Developers choose different tools/stacks for different reasons. Java is great, but it never really delivered on the promise of “write once, run everywhere” (although many would argue with me on this). Some of the disadvantages of Java in regards to desktop apps:
It’s heavy (takes up lots of space, uses lots of memory).
You need the JVM (Java Vritual Machine) on the client.
Desktop theming - it doesn’t keep the operating system’s “native theming”.
Here’s a quick example using the Swing GUI framework:
import javax.swing.*;
public class SwingExample {
public static void main(String[] args) {
JFrame frame = new JFrame();
JButton button = new JButton("Hello there!");
button.setBounds(100,100,200, 40);
frame.add(button);
frame.setSize(400,500);
frame.setLayout(null);
frame.setVisible(true);
}
}
Compile with: javac SwingExample.java
Run with: java SwingExample
Don’t get me wrong - many awesome desktop apps have been written with Java, such as LibreOffice, Eclipse, IntelliJ (Android Studio) etc…All I’m saying is it’s not a magical solution. Sometimes it just doesn’t make sense to roll with Java (and one of the many Java GUI frameworks out there), although sometimes it does
As of Java 9 (some years ago now, I think) the JRE has been split into modules. This means packages compiled for distribution can be smaller. Also the fact that OpenJDK seems to be more prevalent on Linux that the Oracle build of Java, it’s possible that the JRE is being bundled in systems like AppImage now.
One of my favourite Java apps, Freeplane, which I have been using for notes / mindmaps for close to a decade now (and it’s a fork of Freemind which I was using for years before that) is now available as a flatpak, so I’m guessing it either packages a JRE inside the flatpak or uses a flatpak runtime of the JRE.