BT

InfoQ Homepage News WebAssembly Used by Java-to-Web Compiler CheerpJ 2.0 to Port Java Applications to Browsers

WebAssembly Used by Java-to-Web Compiler CheerpJ 2.0 to Port Java Applications to Browsers

Bookmarks

LeaningTech recently released the second major iteration of CheerpJ. CheerpJ 2.0 may convert Java applications into a mix of HTML, WebAssembly and JavaScript, so that developers can run Java applications (including applets) in browsers or integrate Java libraries into web applications. CheerpJ 2.0 uses WebAssembly to improve runtime speed.

CheerpJ 2.0 provides a full (100% of the Java 8 language), modular, optimized Java 8 SE runtime library in WebAssembly and JavaScript. The runtime is complemented by a collection of browser-based native implementations of different functionalities (e.g. multi-threading with web workers, audio with Web Audio, file system access on top of IndexedDB and more). CheerpJ 2.0 newly leverages WebAssembly runtime modules to improve runtime speed and reduce the size of packages with heavy computational cost (e.g. font rendering).

CheerpJ's previous versions shipped over 1MB of JavaScript for a simple increment-a-counter application. CheerpJ 2.0 strives to bring the download size down by shipping only the required components of the runtime. However, after accounting for the gain in parsing time for Wasm modules vs. equivalent JavaScript modules, CheerpJ 2.0 applications may still exhibit a perceptible waiting time for users to start using the application. As a result, CheerpJ does not fit all developers’ use cases. In particular, Stefano De Rossi, LeaningTech’s CEO, emphasized one CheerpJ non-goal:

CheerpJ is not intended for writing a web application from scratch (…), We do not see CheerpJ as a Blazor-equivalent for Java (…)

Rossi detailed the three main use cases that CheerpJ strives to tackle. The first use case relates to the conversion of legacy Java applications and applets. Such legacy applications may see their life extended as they can be distributed, accessed and used on modern browsers. Rossi mentioned that hundreds of legacy educational Java Applets may for instance benefit.

The second use case involves the migration of existing Java clients to browser-based applications, keeping and converting the existing business logic to JavaScript/WebAssembly, while rewriting the user interface in HTML. In the third use case, developers may convert existing Java libraries and integrate them in a web application.

Rossi summarized in an interview with techUK the advantages linked to WebAssembly:

Thanks to Wasm, we can make compilers and conversion tools that translate native Desktop and Mobile applications into standard web applications, that can be used by any device with a browser, irrespective of its operating system and browser vendor.
This means that you can take your existing Java, Flash or C++ applications that are mission-critical and took years to be developed, and port them to HTML5 automatically, with no manual intervention.
Crucially, compiling to WebAssembly means that your organisation does not rely on remote execution and cloud-based virtualisation for application delivery. This keeps maintenance and running costs to a minimum, by using the computational power on the end-user device to run the application

CheerpJ is closed source but free to use for non-commercial purposes, as well as for technical evaluation; other uses may require a license. An online playground is available for developers to write Java code and see it rendered in real-time in the browser.

Leaning Technologies is a computer software company specializing in WebAssembly and compile-to-JavaScript solutions and tools to convert applications into Web Apps. Leaning Technologies strives to provide an automated, low-cost migration and modernization solution for large-scale legacy applications.

Other solutions to compile Java applications into web applications include GWT, TeaVM, JSweet, Vaadin Flow, J2CL and more. The JWebAssembly open source project is currently developing a Java-bytecode-to-WebAssembly compiler.

Rate this Article

Adoption
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

BT

Is your profile up-to-date? Please take a moment to review and update.

Note: If updating/changing your email, a validation request will be sent

Company name:
Company role:
Company size:
Country/Zone:
State/Province/Region:
You will be sent an email to validate the new email address. This pop-up will close itself in a few moments.