Learn CHEERPJ with Real Code Examples

Updated Nov 25, 2025

Explain

CheerpJ lets you run Java applications in the browser without needing JVM installation.

It converts Java bytecode (.class, .jar) into a mix of JS and Wasm.

Provides a browser-based JVM emulation to run complex Java apps.

Supports Java AWT/Swing applications via HTML5 canvas rendering.

Allows enterprise legacy Java applications to be ported to the web with minimal changes.

Core Features

Ahead-of-time Java-to-Wasm/Javascript compiler

CheerpJ Runtime Environment (CJRE)

Browser-based JVM with classloader/Web APIs

Swing/AWT rendering stack mapped to HTML5

Secure sandbox execution

Basic Concepts Overview

Bytecode Translation - convert Java to WebAssembly/JS

CJRE - browser-hosted Java Runtime Environment

Swing/AWT Emulation - map Java UI to HTML5

ClassLoader - dynamic class loading via web

Filesystem Emulation - Java file APIs mapped to virtual FS

Project Structure

index.html - main launcher

cheerpj.js - runtime loader

cheerpj-*-wasm.js - Wasm modules

app.jar - your Java program

assets/ - Additional Java resources

Building Workflow

Prepare Java .jar or .class files

Configure CheerpJ loader

Initialize CJRE in browser

Run main class using cheerpjRunMain

Debug and optimize loading performance

Difficulty Use Cases

Beginner: run a simple Java console app

Intermediate: run Swing UI with buttons

Advanced: migrate legacy multi-jar applications

Expert: integrate CheerpJ with custom JS UI

Auditor: optimize Wasm payload + caching

Comparisons

CheerpJ vs TeaVM: CheerpJ runs *unmodified* bytecode; TeaVM requires source-level transformation

CheerpJ vs GWT: CheerpJ is JVM-compatible; GWT is Java->JS transpiler

CheerpJ vs Go-WASM: CheerpJ targets legacy Java preservation; Go-WASM targets new apps

CheerpJ vs WebAssembly Java Runtimes: CheerpJ has strongest AWT/Swing support

CheerpJ vs Emscripten: Different languages; Emscripten better for C/C++ performance

Versioning Timeline

2017 – CheerpJ initial release

2019 – Strong Swing/AWT support

2021 – CJRE performance improvements

2023 – CheerpJ 2.0, Wasm-focused runtime

2024–2025 – Enhanced enterprise tooling & DX

Glossary

CJRE - CheerpJ Runtime Environment

Bytecode - compiled Java code

Wasm - WebAssembly binary format

Swing/AWT - Java UI frameworks

Classloader - dynamic Java class loader