Home > Enterprise >  How does Java make Windows applications without needing to install other development tools?
How does Java make Windows applications without needing to install other development tools?

Time:06-01

Recently, I’ve been experimenting with some new programming languages just to test the waters. I’ve been trying to make Windows apps.

Any language/library I choose, whether it’s Go, Rust, Dart (Flutter) etc, always need me to install external tools for Windows development. Usually, these are things like the C Build Tools or a C compiler.

What stumps me is that, in Java, you don’t need anything like it. You can use Swing or JavaFX or something, and in a few lines you can have a working Windows application. If you’re wondering, Java was the first language I tried to make a Windows app in (and I did not have any extra tools installed apart from the needed Java ones, such as the JVM, JRE etc). The other languages came later on, and every one of them required some prerequisites like the ones I mentioned above. Plus, Java is C-based which makes it even more confusing how it doesn’t need any other tools to work.

I’ve never tried to do any too in-depth/complicated Java Windows apps, so maybe later down the line I’d need to get the extra tools, but from what I’ve been doing I’ve never needed them.

Anyway, I’m just wandering how/why this is? How does Java just…work? Is it something like the JVM?

CodePudding user response:

tl;dr

Is it something like the JVM?

Yes, the JVM is what enables your Java app to execute on a particular kind of computer.

Details

The Java Virtual Machine (JVM) is a rather large, sophisticated, and highly tuned piece of software that participates in the running of your app. As the name suggests, it virtualizes (pretends) to be a generic kind of computer, and then underneath bridges to the real computer on which it runs. So a Java program can remain blissfully ignorant of the details of the underlying hardware and operating system.

So every JVM implementation is platform-specific. To run a Java app on a Mac, you need a JVM built for macOS and built for that Mac’s CPU architecture (Intel or Apple Silicon/Aarch64). Likewise, to run the very same Java app on your Windows PC, you need a JVM specific to that OS and CPU.

That means every Java app needs a JVM at runtime. Either a JVM must be bundled with your app or a JVM must be already installed.

In olden times, Sun Microsystems (inventor of Java) made partial success in having a JVM pre installed on every computer. Oracle, the current owner of Java, has given up on that idea. They now encourage app developers to bundle a JVM within the app artifact. Oracle has invested significant resources into inventing the Java Platform Module System (JPMS) to enable bundling a slimmed-down minimal JVM with your app, containing only the parts actually used by that app.

This bundled JVM does mean that you must produce various builds of your app. You need a build with a JVM for Windows on x86 32-bit, on x86 64-bit, on Aarch64, etc.

See also the Java JEPs related to tooling to help in packaging your app: jlink and jpackage.

See the Oracle white paper Java Client Roadmap Update of 2020-05.

  • Related