This chapter does not appear in the book.
Scratch is a hugely enjoyable visual programming language, that makes it easy for primary school kids to create interactive stories, games, and animations (and learn programming skills in the process).
The aim of this chapter is to link Scratch and Java by utilizing an experimental feature of Scratch v1.3 (remote sensor connections) which lets Scratch programs communicate with other software or hardware via a TCP socket and message passing.
I develop a small set of Java classes which hide the low-level details of socket creation and message construction and extraction, and use those classes to write several small-to-medium size examples showing how Scratch and Java can work together.
The examples include a Scratch program that utilizes Java as an external time source, and a Java GUI for a Scratch trampoline game. These larger examples show that writing a Scratch/Java application can be a little tricky because of Scratch's threaded nature, an issue that arises when interfacing any language to Scratch.
Another difficulty is the simple nature of the communication between Scratch and Java. Scratch's network protocol only supports messages involving strings and numbers, which makes it hard to implement richer forms of interaction. However, there are some coding techniques that can help matters, which are applicable to any language communicating with Scratch, not just Java.
This chapter doesn't explain how to program in Scratch, but gives an overview of its features, and points to sources of more information.