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.
- Windows: installer (MSI) or portable ZIP
- macOS with Apple chip (M1 and newer): DMG
- macOS with Intel chip: DMG
- Linux: AppImage or DEB package
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.
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 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
- Press ▶ to run your program. Click the stage if the game uses the keyboard. Error messages appear below the editor.
-
Choose Export, then Save for Studio. This saves a
.scratch4jfile. - 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.
VS Code
-
Install the Extension Pack for Java (search for
vscjava.vscode-java-packin the Extensions view). - Download the VS Code starter project and unpack it.
-
Download the library and put it into the project's
+libsfolder.
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.
LibraryAdd 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 |