How does CheerpJ work?
CheerpJ is a WebAssembly-based Java Virtual Machine for the browser. This means Java applications can be executed from the browser with no Java installations. Amazing, right? but… How does it work?
<script> tag. It requires no custom executable component, plugin, or server-side backend.
CheerpJ is very simple to use as it exposes an API for executing standalone Java applications, applets, Java Web Starts, and Java libraries - entirely in the browser. One of the strengths of CheerpJ is that it works directly with Java byte code/JARs, meaning no need to modify or have access to the application’s source code.
CheerpJ assets are static, which makes it easily self-hostable, and we provide a cloud version under the CheerpJ Community Licence (free to use for personal projects and technical evaluations).
CheerpJ is made of the following building blocks:
- A virtualized window manager
- A virtualized file system
- A module for networking support
The CheerpJ Java Runtime Environment
The most important component of the CheerpJ Java runtime environment is its JVM implementation. CheerpJ’s implementation of the JVM is made of an interpreter and a Just In Time compiler (JIT) that work in conjunction in a 2-tier manner:
- The Java byte code runs within an interpreter.
The interpreter does not only deal with initialization and rarely-used code, but also gathers necessary information for JIT-ting. The generated code is very efficient, and the internal optimizer can, among other things, inline and devirtualize calls, which is extremely important for a language such as Java.
The virtualized window manager
What would be of an application without its graphical UI? CheerpJ’s window manager supports Java AWT/Swing by converting windows to a hierarchy of HTML elements and HTML5 canvases.
Swing applications, will render exactly as they do in native. Swing Look&Feel is also supported, including 3rd party ones. Multi-window applications are supported, with keyboard focus being managed as expected. Integration with the system clipboard can be enabled via an initialization option.
The virtualized file system
CheepJ provides multiple filesystem backends to accommodate different application needs, including access to server-hosted files and persistent local storage.File System guide
For same-origin HTTP/HTTPS requests, CheerpJ will be able to transparently use
fetch. More generalized networking is supported via Tailscale, a VPN technology using WebSockets as a transport layer. It can support many different networking scenarios, including access to private network services, peer-to-peer connections between users and access to the wider internet via a user/application provided exit node.