
Has JavaScript displaced Java as the new “Write once, run anywhere” (WORA) programming language? It all depends on your perspective. And with technologies such as WebAssembly arriving on the scene, Java could get a boost in a newfangled “write once, compile anywhere” paradigm.
Java will run wherever the JVM works, providing portability across many operating systems and hardware platforms including mobile and embedded devices.
But JavaScript, always crucial to in-browser applications, now works for desktop applications via technology such as the Electron framework, for mobile applications via frameworks like React Native, and for web back ends through Node.js and Deno, notes developer Shalitha Suranga, author of the Neutralino JavaScript/TypeScript framework. JavaScript even works for Internet of Things (IoT) and robotics development, through tools such as NodeMCU.
“Nowadays, whatever we can do with Java can be done with JavaScript as well,” said Suranga, a software engineer at digital products builder 99x and an Apache project management committee member. He recently authored an opinion piece on Medium arguing that JavaScript, not Java, was today’s WORA language.
JavaScript: From web browsers to servers to devices
While Suranga’s Medium article declared JavaScript to be immortal and Java to be slowly dying, he would not say that JavaScript is killing Java as a programming language. Rather, Suranga argues that in all those places where Java shined — desktop applications, web servers, web clients, mobile apps, smart TV applications — JavaScript is now performing those roles better than Java.
In particular, JavaScript rules the web browser, where Java applets failed to gain a foothold. Even for Android mobile apps, Java has been giving way to cross-platform JavaScript frameworks like Ionic, React Native, and NativeScript.
But at Oracle, which oversees development of the standard edition of Java, the notion of Java’s supposed decline in favour of JavaScript was met with skepticism. “We’ve been hearing Java’s dead for 15 years now and it remains an extremely important platform,” said Chad Arimura, vice president of developer relations for the Java platform group at Oracle. The company published the latest version of standard Java, Java 16, on March 16.
At Azul, a provider of Java runtimes that compete with Oracle’s, the company emphasised not only the WORA advantages of the Java Virtual Machine but also the scalability the JVM provides, particularly on the server side.
“Yes, it’s true that JavaScript is totally cross-platform because of the fact it’s in the browser and is running across whatever platform you want to run it on,” said Simon Ritter, Azul’s deputy CTO, adding, “I think that Java still has the big advantage from the point of view of performance on the server side, definitely.”
WebAssembly: New life for Java?
Technologies such as WebAssembly and Spring Native introduce a new twist on the WORA concept. By allowing various programming languages to be compiled to portable or native executables, they essentially decouple the language from the runtime platform. Developers can use Java without the JVM.
The WebAssembly binary instruction format serves as a mechanism for in-browser programming, with WebAssembly a compilation target for other languages to run on the web. The JWebAssembly compiler project in development aims to run Java natively in the browser via WebAssembly. WebAssembly also can be deployed on the server via the Wasmer runtime. With WebAssembly, Java could go anywhere JavaScript goes.
Nevertheless, Suranga still sees JavaScript offering benefits in ease of use and dynamic features. While an argument could be made that WebAssembly might make Java immortal, enabling Java to be used in web development without needing JavaScript, developers are still likely to end up delving into JavaScript, Suranga argued.
Spring Native, meanwhile, allows Java programming to be used to build standalone executables, sans the JVM. Spring Java (and Kotlin) applications are compiled to native images. The GraalVM multi-language runtime is leveraged with Spring Native, which has just moved to a beta release stage.