What is the difference between Java & WebAssembly?
Maciej Dziardziel
Maciej Dziardziel, studied at University of Zielona Gora
Answered Oct 13, 2016 · Author has 308 answers and 280k answer views
why don't web browsers integrate Java instead
It is a proven technology
Yes. Its proven not to work well with browsers. They have already tried it, and it ended up bad. First, results java applets were producing were not accessible through DOM, so sites who used them were not visible to search engines. Second, java applets had its own ui that looked out of place on every platform, and worked very differently then ui elements in the browser - this confused users. Third, throwing jvm as is turned out to be massive source of security holes, and Sun/Oracle was not rushing with fixing them (or they just couldn’t keep up). And that’s just a fraction of problems with using java without redesigning it for browsers - it was also sluggish, drained a lot of power, development tools were lacking.
So here are few things that webassembly does differently:
- Its being delivered in small parts and initially tries to be compatible with all technologies and mechanisms browsers already have to make transition easy.
- Browser vendors have a say about how it works and how it integrates with browsers.
- Its aiming at being integral part of the browser, not something alien bolted on it. It will use all APIs browser have and will have, not reinventing its own wheels.
Have java choose this path long time ago, we could be using it now, but its designers believed that java is so hot everyone will just take it as it is.
Aren't both Java and web assembly byte code
Looking from far away, they both are, but evil lurks in details. Java bytecode is made to run java the language (with some concepts from other languages added later). Webassembly does not favour specific language, but aims to support features needed by wide range of languages using various paradigms. The path that leads from bytecode to execution is also not exactly the same. Those differences might be subtle, but led to java not being best choice for webassembly.
Anton Carver
Anton Carver, former Staff Software Engineer at Google (2003-2016)
Updated Dec 1, 2018 · Author has 10.5k answers and 1.5m answer views
Overall Java bytecode can be thought of as a bit higher level, WASM is more like assembly as its name suggests.
Some notable differences are:
Java byte code depends on automatic garbage collection. i.e. it explicitly creates objects and never explicitly destroys them. WASM doesn’t know about objects (though future versions may offer support for some kind of automatic garbage collection).
Java bytecode is type-safe. WASM allows memory to be read or written as if it contained any type (weak typing - like assembly language).
There is no direct model of memory in Java bytecode. You access variables, fields of an object or items in an array, but never a memory location by address. In WASM you operate on memory as if it was a big array.
Java bytecode will access fields, functions, and types symbolically. WASM will access them directly by indexing, wrappers are needed when interacting with symbolic languages (like JavaScript).
Java has an explicit memory model for shared memory computing. WASM is only supporting sequential computation at MVP (minimal viable product). A shared memory is in the pipeline for WASM and will offer a weak memory model (like C++).
Java code may depend on native support in the core library i.e. the JRE is monolithic. There is no assumed base or runtime in WASM at MVP. Though it is likely that the Web version of WASM will expose the DOM via an API.
So overall there are a lot more differences than similarities.
345 views · View 9 Upvoters