Learn Cheerpj - 10 Code Examples & CST Typing Practice Test
CheerpJ is a WebAssembly-based Java-to-JavaScript/WebAssembly compiler and runtime that allows running unmodified Java applications directly inside the browser without plugins. It converts Java bytecode into WebAssembly + JavaScript, enabling full client-side execution of existing JVM applications, applets, and libraries.
View all 10 Cheerpj code examples →
Learn CHEERPJ with Real Code Examples
Updated Nov 25, 2025
Code Sample Descriptions
Simple CheerpJ Java Program
# cheerpj/demo/Main.java
public class Main {
public static void main(String[] args) {
System.out.println("Hello, CheerpJ!");
}
}
A basic Java program compiled with CheerpJ that prints 'Hello, CheerpJ!' in the browser console.
CheerpJ Java Button Click
# cheerpj/demo/ButtonClick.java
import javax.swing.*;
import java.awt.event.*;
public class ButtonClick {
public static void main(String[] args) {
JFrame frame = new JFrame("CheerpJ Button");
JButton button = new JButton("Click Me");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("Button clicked!");
}
});
frame.add(button);
frame.setSize(200,200);
frame.setVisible(true);
}
}
A Java program that creates a button and prints to console when clicked (via CheerpJ).
CheerpJ Java Input Dialog
# cheerpj/demo/InputDialog.java
import javax.swing.*;
public class InputDialog {
public static void main(String[] args) {
String name = JOptionPane.showInputDialog("Enter your name:");
System.out.println("Hello, " + name + "!");
}
}
Shows an input dialog and prints user input to console.
CheerpJ Java Conditional Output
# cheerpj/demo/Conditional.java
public class Conditional {
public static void main(String[] args) {
boolean isTrue = true;
if (isTrue) {
System.out.println("Condition is true");
} else {
System.out.println("Condition is false");
}
}
}
Prints different messages based on a condition.
CheerpJ Java Loop Example
# cheerpj/demo/Loop.java
public class Loop {
public static void main(String[] args) {
for (int i = 1; i <= 5; i++) {
System.out.println("Item " + i);
}
}
}
Prints a list of items using a loop.
CheerpJ Java Timer Example
# cheerpj/demo/Timer.java
import java.util.Timer;
import java.util.TimerTask;
import java.util.Date;
public class TimerExample {
public static void main(String[] args) {
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
public void run() {
System.out.println(new Date());
}
}, 0, 1000);
while(true) {}
}
}
Uses a timer to print current time every second.
CheerpJ Java Swing Label Update
# cheerpj/demo/LabelUpdate.java
import javax.swing.*;
import java.awt.event.*;
public class LabelUpdate {
public static void main(String[] args) {
JFrame frame = new JFrame("Label Update");
JLabel label = new JLabel("Initial Text");
JButton button = new JButton("Update");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
label.setText("Updated Text");
}
});
frame.setLayout(new java.awt.FlowLayout());
frame.add(label);
frame.add(button);
frame.setSize(300,100);
frame.setVisible(true);
}
}
Updates a JLabel when a button is clicked.
CheerpJ Java Dialog Example
# cheerpj/demo/Dialog.java
import javax.swing.*;
public class Dialog {
public static void main(String[] args) {
JOptionPane.showMessageDialog(null, "Hello, CheerpJ Dialog!");
}
}
Shows a message dialog using JOptionPane.
CheerpJ Java Array Loop
# cheerpj/demo/ArrayLoop.java
public class ArrayLoop {
public static void main(String[] args) {
String[] items = {"A", "B", "C"};
for (String item : items) {
System.out.println(item);
}
}
}
Iterates over an array and prints each element.
CheerpJ Java Nested Loops
# cheerpj/demo/NestedLoops.java
public class NestedLoops {
public static void main(String[] args) {
for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= 3; j++) {
System.out.print(i*j + " ");
}
System.out.println();
}
}
}
Uses nested loops to print a pattern.
Frequently Asked Questions about Cheerpj
What is Cheerpj?
CheerpJ is a WebAssembly-based Java-to-JavaScript/WebAssembly compiler and runtime that allows running unmodified Java applications directly inside the browser without plugins. It converts Java bytecode into WebAssembly + JavaScript, enabling full client-side execution of existing JVM applications, applets, and libraries.
What are the primary use cases for Cheerpj?
Running legacy Java Swing/AWT desktop apps in the browser. Migrating Java Applets to modern WebAssembly environments. Enterprise internal tools requiring Java libraries. Embedding Java libraries inside JS/Wasm web apps. Preserving old JVM-based simulations, tools, and educational software
What are the strengths of Cheerpj?
Run unmodified Java applications in browser. No need to rewrite Java -> JS manually. Great for preserving legacy enterprise tools. Stable runtime with good browser compatibility. Strong support for complex UI frameworks
What are the limitations of Cheerpj?
Performance lower than native JVM. Binary payload size can be large. Not ideal for highly interactive or real-time apps. Limited debugging compared to JVM tools. Not suitable for low-latency games
How can I practice Cheerpj typing speed?
CodeSpeedTest offers 10+ real Cheerpj code examples for typing practice. You can measure your WPM, track accuracy, and improve your coding speed with guided exercises.