As far as I understood, JavaScript cannot be compiled ahead of time because of it's dynamic nature. So Interpretation and just in time compilation happens at run time, that affects JavaScript performance. So WebAssembly comes into picture. Languages can be compiled ahead of time into intermediate format (WASM). This gives good performance since there is less runtime overhead.
My question is why JVM cannot be used in place of WebAssembly VM. Java compiled into intermediate format (bytecode). This byte code can be given to browser and JVM can execute it. JVM also supports JIT which helps to achieve near native performance.
So what is the need for new WebAssembly. Why can't JVM be integrated into browser and achieve high performance by leveraging the existing most popular Java language.
Personally, my biggest takeaway from the differences between JVM and WebAssembly is that Wasm is platform-independent and provides near native speed for whatever architecture you're running on all with support for many languages, guaranteed security and the fact that you can stream the Wasm binary in the browser.
JWebAssembly, from I-Net Software, is a Java bytecode to WebAssembly compiler that takes Java class files as input and generates WebAssembly binary format (. wasm file) or text format (. wat file) as output. The target is to run natively in the browser with WebAssembly.
Java, for example, is executed with the JVM (Java Virtual Machine) while . NET languages are executed by the CLR (Common Language Runtime). WebAssembly is a bytecode format that any WebAssembly-capable runtime can execute.
WebAssembly (abbreviated Wasm) is a binary instruction format for a stack-based virtual machine. Wasm is designed as a portable compilation target for programming languages, enabling deployment on the web for client and server applications.
There are a great many reasons why the JVM was not deemed a suitable runtime in place of WebAssembly ...
As a general observation, WebAssembly was designed to support multiple languages on the web. The JVM was designed to support Java on the desktop. It doesn't make either one better than the other in a more general sense.
Finally, the JVM was integrated with the browser (Java Applets), but that didn't work out in the end!
A quote from the High-Level Goals of WebAssembly:
a Minimum Viable Product (MVP) for the standard with roughly the same functionality as asm.js, primarily aimed at C/C++;
So their original goal was running C/C++ program in a web browser, not running Java code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With