# Running Java projects

Source: https://browsercode.io/docs/ide/java

Index of every BrowserCode page: https://browsercode.io/llms.txt

Compile and run Java on CheerpJ, choose a Java version and share projects.

Java projects run on [CheerpJ](https://cheerpj.com), a JVM for the browser, instead of BrowserPod. CheerpJ does not need the browser features that BrowserPod requires, so Java projects work on phones, iPads and browsers that cannot run Node.js projects.

Start from the [Java playground](https://browsercode.io/java). Its examples are grouped under four headings:

-   **Basics**: from [Hello World](https://browsercode.io/java?example=helloworld) to programs that read console input.
-   **Graphics**: Swing and AWT programs, such as the [Swing example](https://browsercode.io/java?example=swing) and the Game of Life.
-   **Algorithms**: for example, animated sorting and maze search.
-   **Language features**: for example, reflection and annotations.

The same examples are listed in the sidebar, under the IDE entry.

## Choosing a Java version

Use the header to switch between Java 8, 11, 17, 21 and 25. Examples start on Java 25. All examples run on every version, but two use newer syntax and have a classic variant: Hello World, which uses Java 25 syntax, and Shapes, which needs Java 21.

If you have not edited the example, switching to an older version loads the classic variant. Once you edit the code, switching version leaves it unchanged.

## Running your code

**Run** compiles every `.java` file in the project and starts the program. Compiler errors and warnings are shown in the editor at the line and column they refer to, until the next build.

If one class has a `main` method, that class runs. If several do, a selector appears next to **Run** so you can choose one. The choice is saved in shared links.

### How code is compiled

BrowserCode compiles your code with `javac`, the standard compiler from OpenJDK. It runs in your browser on CheerpJ, like your program, and uses the same Java version you selected. No code is sent to a server. `javac` runs with `-Xlint`, which enables all recommended warnings.

## Console and Display

The Output tab is a terminal. Input you type goes to `System.in`, and Ctrl+D closes the stream.

Java projects show a Display instead of a web preview. AWT and Swing windows are drawn there. The Display is empty until your program opens a window, and it is cleared on each run.

Java projects have no shell and no package manager yet, so only the standard library is available. Dependency support is planned.

## Sharing a project

**Share** encodes the project in a link, including the files, the Java version and the selected main class. Nothing is stored on a server, so the link works as long as browsercode.io is reachable.

Large projects produce long links. If a link stops working after you paste it somewhere, it has probably exceeded that tool's URL length limit.

To link to a built-in example or add a link to a README, see [Linking to BrowserCode](https://browsercode.io/docs/linking).

## One Java project at a time

All Java tabs on a site share one storage area. If you open a second Java tab, it offers to take over the session, which closes it in the first tab. Java embeds on different sites do not conflict, because browsers keep each site's storage separate. See [Embedding BrowserCode](https://browsercode.io/docs/embedding).

- [Next Running coding agents](https://browsercode.io/docs/agents)
