is java 9 and above still platform independent or not after this module system has been introduced?

547 views Asked by At

I am not able to understand that after module system is introduced in our java language. Is java9 and above still platform independent or not ? I am asking this question because I have read that now every application will have its own jre inside it. So, how will this single jre run on all OS, like windows, Linux, or Mac OS.

4

There are 4 answers

0
Basil Bourque On BEST ANSWER

You are conflating two different changes recently made to the Java platform:

  • Retiring of Java Web Start & Applet technologies
  • Modularization

Retiring desktop-technologies

Recently Oracle announced the phasing out of the Java Web Start technologies, in addition to the already-deprecated Applet technology. See item JDK-8184998 in Java 9 Release Notes:

Java Deployment Technologies are deprecated and will be removed in a future release

Java Applet and WebStart functionality, including the Applet API, The Java plug-in, the Java Applet Viewer, JNLP and Java Web Start including the javaws tool are all deprecated in JDK 9 and will be removed in a future release.

End-users will no longer be encouraged to install a JDK or JRE on their computer.

For more details, see the eight-page 2018-03 white paper from Oracle, Java Client Roadmap Update.

So then, how are developers of Swing or JavaFX apps to deliver their software to the end-user?

Oracle suggests packaging up your app along with a JVM & JRE for delivery as a single launch-ready applications on that appears on the client to be just another app alongside the native apps. Such “double-clickable” app-packaging has been commonly done on the Mac since the beginning of Java. But what was once an obscure art on other host environments (Linux, BSD, Windows, etc.) will now be the norm, as it is on macOS.

In yesteryear, bundling a Java runtime with your app required jumping over some licensing hurdles. The legalities have eased with arrival of the open-source OpenJDK project, and possibly with other implementations.

You will need to prepare different releases of your app for each hosting environment. While your Java code runs independently of the host OS, the JVM is built of native code to interact with one specific kind of host. So you will need to build a Linux release with a Linux JVM, a macOS release with a macOS JVM, and so on. While that may seem like a downer, the upside is that you no longer need to worry about users having the wrong JVM version installed, or no JVM at all. Now the JVM’s presence and version are under your control. Your end-users and customers will no longer need to be aware that your app is Java-based.

Modularization

That need for app-packaging has nothing to do with the modularization of Java. As I said, it has been done for decades on the Mac.

What modularization brings to the party is that the JVM/JRE you bundle into your delivered app can be customized to contain only the Java Modules actually utilized by your particular app. This results in a smaller size, so your finished app is smaller, downloads are faster, less storage is used, and your app may load faster.

The open-source jlink “Java Linker” tool helps with the packaging work, so you can assemble and optimize a set of modules and their dependencies (only the ones actually called by your app) into a custom run-time image. This modular run-time image format is defined in JEP 220.


On a related note, you may want to read the white paper Java Is Still Free to understand how and where to obtain a Java implementation for your app, and what support may or may not be offered in either free-of-cost or paid releases.


By the way, you may find helpful this Answer on a related Question, with a flowchart of choosing various sources of a Java implementation.

1
Rene Knop On

The module system doesn't influence the OS independency of java in general. Java applications that make use of the module system need to be run in a JRE. This can be either an OS specific pre-installed JRE as usual or a tailored runtime image (application embedded JRE) created with JLink.

The module systems main purpose is to provide you a managed way to split your application into different logical modules. E.g. into different .jar files that can be loaded at runtime - no matter on which operating system.

In summary, you have the following options:

  • Make sure that your client has the right JRE pre-installed. This could be dangerous, because (normally) you are not in control of his updating behavior.

  • Ship your application together with an official JRE.

  • Tailor your own, application and OS specific runtime image using JLink. Ship it bundled with your application.

    But, suppose I do not know what OS my client would be running so how the server will decide what image he should give to him. i.e., a Mac Image, a Linux Image or a Windows exe.

    You have to know the target OS and deliver the right runtime image.

0
Michael Berry On

Is java9 and above still platform independent or not ?

Yes. It's as platform independent as it ever was. The module system has nothing to do with platform independence.

now every application will have its own jre inside it.

It doesn't have to, but it's more and more recommended as time goes on since fewer people have Java installed separately on their systems. This used to be a given, but that number has been declining for the last decade or so, and now (outside of Java developers) pretty much no-one has a standalone JRE installed.

how will this single jre run on all OS

It won't. You will bundle a separate JRE for each platform you want to distribute for. But JRE's for all platforms are still freely available, and the same Java code will still run on a JRE for any platform.

1
Peter Lawrey On

While Java 9 makes it easier to ship a JRE which is more compact and specific to the needs of an individual application, you are not required to do so. If you were already planning to ship a JRE with your application it can be smaller with Java 9 than earlier versions.

It doesn't mean you have to ship a JRE, an application which wasn't shipped with a JRE is unlikely to start shipping with one now, and in fact Java 11 only ships as a JDK.

From this link on Java 9 features;

JLink allows you to create custom runtime images that only consist of your application modules and those JRE modules that your application requires. The result is likely a smaller runtime image, which uses fewer resources than a default JRE.