Scratch for Java

Install

You can write Scratch for Java in three places. The code is the same in all of them, so you can start in one and move to another later.

You need Good for
Browser Nothing Trying it out, the first lessons, homework
Studio Java and the library are included. Your own computer or the school's, also offline
VS Code or another editor Java 17 or newer and the library Courses that already use one

Scratch for Java Studio

Studio is the desktop editor for learning Scratch for Java. You can work offline, with Java and the library included.

Start a lesson in Studio

Choose Start a guided lesson on the start screen, then open the first lesson. Press ▶ to run the project and Ctrl+S (Cmd+S on Mac) to save. You can also bring over a project from the browser.

Studio start screen with the Start a guided lesson link below the project choices

In the editor, look up familiar Scratch blocks to see the Java that goes with them. You can arrange sprites in the stage designer while your Java code is open beside it. Studio points out errors as you type.

Studio showing Scratch blocks, Java code and the stage designer side by side

Studio is in alpha. See the Studio project on GitHub for features and feedback.

In the browser

Every code box with a ▶ on this site is a real editor. Start with Your first program.

From the browser to Studio

  1. Press ▶ to run your program. Click the stage if the game uses the keyboard. Error messages appear below the editor.
  2. Choose Export, then Save for Studio. This saves a .scratch4j file.
  3. Double-click the file to open it. In Studio, press ▶ to run the imported project and use Ctrl+S or Cmd+S to save changes. If double-clicking doesn’t work on a school computer, export a ZIP from the browser and import it through Studio’s Project menu.

To continue in the browser, choose Save as ZIP under Export instead. On the other computer, use Open in the editor to load the ZIP. The browser saves your edits locally. You can take the exported file with you or hand it in.

The export dialog with the file name and the Save for Studio button

VS Code

  1. Install the Extension Pack for Java (search for vscjava.vscode-java-pack in the Extensions view).
  2. Download the VS Code starter project and unpack it.
  3. Download the library and put it into the project's +libs folder.

The starter project already has this line in .vscode/settings.json. It tells VS Code where the library is:

"java.project.referencedLibraries": ["+libs/*.jar"]

Studio keeps the library in +libs too, so a project opens in both.

From the browser to your own computer

The examples in the browser start with a short void main():

void main() {
  Window myWindow = new Window(480, 360);
  myWindow.setStage(new MyStage());
}
Where you work What you need
Browser The editor on the page. It provides the Scratch for Java classes.
Studio Java is included. Studio opens the browser export.
Another editor with Java 25 or newer The library and the relevant import lines. You can use short void main() in a compact source file.
Another editor with Java 17 to 24 The library and the relevant import lines. Use the full form below.

Desktop games also require OpenGL 3.3 or newer (4.1 on macOS). If you run outside Studio on a Mac, follow the macOS launch instructions.

Here is the full form. Save it as MyStage.java.

import org.openpatch.scratch.*;
 
public class MyStage extends Stage {
  public MyStage() {
    Sprite bunny = new Sprite();
    bunny.addCostume("bunny1_stand");
    this.add(bunny);
  }
 
  public static void main(String[] args) {
    Window myWindow = new Window(480, 360);
    myWindow.setStage(new MyStage());
  }
}

Downloads

The desktop library, version 7.2.1.

Library

Add the sources and the Javadoc too. Then your editor can show what each method does:

Sources Javadoc VS Code starter project

Does your course use the classes of the NRW Zentralabitur (List, Queue, …)? Then use the NRW version instead.

Teachers can get every tutorial as a ready project in the course pack.

Maven

For a desktop game, add both dependencies under <dependencies>. scratch provides the Java API, and scratch-desktop provides the window and sound.

<dependency>
  <groupId>org.openpatch</groupId>
  <artifactId>scratch</artifactId>
  <version>7.2.1</version>
</dependency>
<dependency>
  <groupId>org.openpatch</groupId>
  <artifactId>scratch-desktop</artifactId>
  <version>7.2.1</version>
</dependency>

The extensions are artifacts of their own, with the same group and version. The library download above and Studio contain all of them.

Artifact For
scratch-actions controls players can change
scratch-ui buttons, sliders and menus
scratch-gamepad game controllers
scratch-save saving progress
scratch-tiled maps from the Tiled editor
scratch-drawing sprites that draw themselves
scratch-recorder recording the stage as a GIF
Install

Create Shareable URL

Select Sections