Leanpub Header

Skip to main content

Java Programming for Raspberry Pi: A Hands-On Guide to Electronics and IoT Projects (2026 edition)

A lot of small and bigger examples to introduce you to Java, JavaFX, Pi4J, Spring, Queues... with hardware projects on the Raspberry Pi.

Image

Get started with the latest versions of Java, JavaFX, Pi4J, Spring, and so much more. Learn the power (and fun!) of experimenting with electronics. All explained in many small and easy-to-understand examples.

Minimum price

$9.99

$19.99

You pay

$19.99

Author earns

$15.99
$

...Or Buy With Credits!

You can get credits with a paid monthly or annual Reader Membership, or you can buy them here.
PDF
EPUB
WEB
499
Readers
476
Pages
84,150Words
About

About

About the Book

When I first managed to blink an LED connected to a Raspberry Pi with Java, I was super excited! Controlling physical things with some lines of code is magic! This book covers a lot of information and history about Java itself, as well as how to install it on the Raspberry Pi. Also, there are many tips and tricks to become a better developer. But, above all, there are many simple examples of these and even more other topics:

  • The magic of Bits and Bytes and solving the confusion of Java signed values with the help of an LED number display.
  • Beautiful user interfaces made with JavaFX so you can interact with the hardware.
  • Pi4J applications to be able to control different types of hardware like LEDs, buttons, displays, LED strips, relais boards, and more. A full chapter explains how easy it is to control electronics with Pi4J in combination with single-file applications with JBang.
  • Spring applications so you can interact with your Raspberry Pi via web interfaces.
  • How to set up a queue to send and receive messages to and from Arduino boards or other Raspberry Pi's.
  • Interviews with some of my heroes: Karen Mouws - STEM and diversity, Trisha Gee - IntelliJ IDEA, Marit van Dijk - IntelliJ IDEA, Xiaokai He - Visual Studio Code, Simon Ritter - Azul Zulu JDK, Alexander Belokrylov - BellSoft Liberica JDK, Jakob Jenkov - Java tutorial site on jenkov.com, Geertjan Wielenga - Foojay.io, Johan Vos - OpenJFX, JavaFX and GluonHQ, Gerrit Grunwald - Java, JavaFX, TilesFX, Robert Savage - Pi4J, Max Rydahl Andersen - JBang, Mark Heckler - Spring, Vlad Mihalcea - JPA, Hibernate, Almas Baim - FXGL.
  • And a lot of other inspirational ideas and getting-started examples to be able to build your dream do-it-yourself project.

My goal was to collect all the information that would have been bundled when I started my experiments with Java on the Raspberry Pi. If you are new to Java, you will learn the language bit by bit by following the examples. As an experienced Java programmer, you will learn how to extend your knowledge and control the world with simple and inexpensive components.

Author

About the Author

Image
Frank Delporte

Software developer and Java Champion with over 30 years of experience in video, multimedia, technical project management, digital signage, and (web) programming.

At work focusing on Java, but also used or using ASP.NET, C#, JavaScript, SQL Server, Flex, CSS, HTML5, Java, Eclipse, Qt...

I love to KISS (Keep It Simple, Stupid) and try to do this in everything I do.

Once a month lead coach of the CoderDojo Belgium club in Ieper, where we teach children (7-18) the fun of programming with Scratch, Arduino, Lego Mindstorms, and Minecraft...

Leanpub Podcast
Image

Episode 234

An Interview with Frank Delporte

Contents

Table of Contents

Introduction

  1. Content Overview
  2. Content Updates
  3. Updates During 2022
  4. Updates During 2023
  5. Updates During 2024
  6. Updates During 2025
  7. Updates During 2026
  8. About Me
  9. Just a Thought: Switching Social
  10. Sources and Scripts Used in this Book
  11. Where to Find Them
  12. Get the Sources
  13. Styling Used in this Book
  14. Read the README!
  15. Guidelines
  16. Example
  17. What’s Next?
  18. Thanks To…
  19. Just a Thought: Impostor Syndrome

Tools and Hardware Used in this Book

  1. Raspberry Pi’s Used for this Book
  2. Raspberry Pi Operating System
  3. Connections between Raspberry Pi and Breadboard
  4. Software Tools on the Raspberry Pi
  5. Linux Commands Crash Course
  6. Firefox
  7. VNC Server
  8. Enable SSH on the Raspberry Pi
  9. Free Software Tools on PC
  10. Integrated Development Environment aka IDE
  11. Remote Connection to a Raspberry Pi (SSH)
  12. Wiring Diagrams
  13. Schematic Drawings
  14. Hardware Components
  15. Resistors
  16. LEDs
  17. RGB-LED
  18. LED Strips
  19. Shopping List
  20. Raspberry Pi
  21. Electronics
  22. Safety Instructions
  23. Electrical Safety
  24. Soldering Safety
  25. Component Safety
  26. General Workshop Safety
  27. Just a Thought: Learn by Educating
  28. Interview with Karen Mouws

Choosing an IDE

  1. IntelliJ IDEA
  2. Using IntelliJ IDEA with the Example Projects
  3. Interview with Marit van Dijk
  4. Interview with Trisha Gee
  5. Visual Studio Code (VSC)
  6. VSCodium the Free Non-Tracking Alternative to VSC
  7. Java Development with Visual Studio Code
  8. Using Visual Studio Code on the PC with Code on the Raspberry Pi
  9. Interview with Xiaokai He

About Java

  1. History
  2. Java Files Versus Byte Code
  3. Java Made Easier For Starters
  4. JVM Versus JRE Versus JDK
  5. JVM = Java Virtual Machine
  6. JRE = Java Runtime Environment
  7. JDK = Java Development Kit
  8. Version History
  9. STS versus LTS
  10. JDK Providers
  11. Oracle
  12. Adoptium Temurin
  13. Azul Zulu Builds of OpenJDK
  14. Interview with Simon Ritter
  15. BellSoft Liberica
  16. Interview with Alexander Belokrylov
  17. Installing the Java JDK
  18. Install Java JDK on a Windows PC
  19. Install Java JDK on a Linux PC or macOS with SDKMAN
  20. Install Java JDK on a Raspberry Pi
  21. Java Crash Course
  22. HelloWorld! Running a Single-File Java-application
  23. Using the Start-up Arguments
  24. Working with Numbers
  25. If, Then, Else
  26. Enum and Switch
  27. Using Methods
  28. Using Objects
  29. Reading a Text File
  30. Using Streams
  31. What’s Next?
  32. Some of the Changes Between Java Versions
  33. Changes Between Java 8 and 11
  34. What’s Next After Java 11?
  35. Interview with Jakob Jenkov
  36. Foojay.io
  37. Foojay Today
  38. Comprehensive Search
  39. Foojay Podcasts
  40. Interview with Geertjan Wielenga
  41. Just a Thought: Abbreviations

The Raspberry Pi

  1. History of Raspberry Pi
  2. Raspberry Pi, The Company
  3. Rasperry Pi, The Foundation
  4. Raspberry Pi Product Line
  5. Major Versions
  6. Board Versions
  7. Raspberry Pi Pins
  8. Power and Ground
  9. Digital GPIO
  10. Pin Punctions
  11. Universal Asynchronous Receiver and Transmitter (UART - Serial)
  12. General Purpose Clock (GPCLK)
  13. Inter Integrated Circuit (I²C)
  14. Serial Peripheral Interface (SPI)
  15. Pulse-Width Modulation (PWM)
  16. Header Types
  17. 40-pin Header
  18. 26-pin Header - Type 1 and 2
  19. 8-pin Header
  20. Different Pinning Numbering Schemes
  21. Board (pin) Number
  22. BCM Number
  23. WiringPi Number

What is Maven?

  1. Install Maven
  2. On Windows PC
  3. On Raspberry Pi
  4. Generate a new Maven Project
  5. Project Structure
  6. A Minimal pom.xml Example
  7. Maven pom-files Used in this Book
  8. Add Application Logging with Maven and log4j

About JavaFX

  1. History
  2. Interview with Johan Vos
  3. Sample Libraries to Extend JavaFX
  4. TilesFX
  5. FXRibbon
  6. ControlsFX
  7. PickerFX
  8. Interview with Gerrit Grunwald
  9. JFX Central
  10. Minimal JavaFX Sample Application
  11. Add New Archetypes to Maven
  12. Creating an Empty Application
  13. Running the Empty Application from Visual Studio Code
  14. Running the Application on the Raspberry Pi
  15. Example 1: TilesFX Dashboard
  16. Wiring and Testing in the Terminal
  17. Blink an LED with Java
  18. Building our First JavaFX Application
  19. Run the Application on PC
  20. Run the Application on the Raspberry Pi
  21. Conclusion
  22. Start a Java Application when the Raspberry Pi Starts
  23. Disable Screensaver
  24. Example 2: Interact with an I²C Relay Board
  25. Enable and Test I²C
  26. Coding the I²C Controller Application
  27. Running the Relay Controller on the Raspberry Pi
  28. Example 3: Build a UI with FXML
  29. Generate an Empty FXML project as a Starting Point
  30. Scene Builder

Bits and Bytes

  1. Convert Bits to a Numeric and HEX Value
  2. Calculate a Byte Value
  3. Value Ranges in Java
  4. Difference Between Byte, Short, Integer and Long
  5. Minimum and Maximum Values in Java
  6. Signed Versus Unsigned
  7. Conclusion
  8. What Can We Do With This?
  9. Web Colors
  10. Controlling a Numeric Segment Display

Pi4J

  1. History of Pi4J
  2. Version Overview
  3. Interview with Robert Savage
  4. Programming with Pi4J and JBang
  5. Sources
  6. What is JBang and How to Use It?
  7. Interview with Max Rydahl Andersen
  8. Digital Output: RGB-LED
  9. Digital Input: Button
  10. Digital Output and Input: Distance Sensor
  11. PWM: Fading a LED
  12. SPI: 8x8 LED Matrix with MAX7219
  13. I2C: LCD-display with the Weather Forecast
  14. SPI and I2C: BME280 sensor
  15. Maven Example with a LED and Button
  16. Wiring
  17. Building the Application
  18. Maven pom.xml File
  19. Initializing Pi4J
  20. Output Pi4J Context Information
  21. Handle the Button Presses
  22. Toggling a LED
  23. Closing the Application
  24. Steps to Run this Application on your Raspberry Pi
  25. Building a Game with Pi4J and FXGL
  26. What is FXGL?
  27. Interview with Almas Baim
  28. Joystick Wiring
  29. Game Application Code
  30. Build and Run the Game

Serial Communication

  1. About jSerialComm
  2. Serial Examples
  3. Serial Communication Example with an Arduino
  4. Pixelblaze Output Expander

Spring Boot

  1. What is Spring Boot?
  2. What is Spring Initializr?
  3. Interview with Mark Heckler
  4. Example 1: Minimal Web Server on the Raspberry Pi
  5. Start from the Initializr Project and Modify pom.xml
  6. Application Properties
  7. Image Controller
  8. Swagger Config
  9. Run on the Raspberry Pi
  10. Conclusion
  11. Example 2: Database REST-service for IoT Data on Raspberry Pi
  12. pom.xml Settings
  13. Creating the Database Entities
  14. Storing Data in the Database
  15. Adding the REST services
  16. Adding Swagger
  17. Running the Application and Using the REST Services
  18. Configuration to Run on the Raspberry Pi
  19. Conclusion
  20. Interview with Vlad Mihalcea
  21. Example 3: REST-service on the Raspberry Pi to Toggle an LED
  22. Info REST-controller
  23. GPIO Manager
  24. GPIO REST Controller
  25. Running the Application on a Raspberry Pi
  26. Conclusion
  27. Example 4: Reactive Data
  28. The Code
  29. Running the Streaming Application on the Raspberry Pi
  30. Conclusion

Message Queues

  1. Using Mosquitto on the Raspberry Pi
  2. Installation
  3. Testing Mosquitto on the Raspberry Pi
  4. Example 1: Share Data Between Raspberry Pi and PC
  5. Modifying pom.xml and module-info
  6. Connecting and Publishing to Mosquitto
  7. Subscribing to Mosquitto
  8. The User Interface
  9. Example 2: Control Arduino from JavaFX via Mosquitto
  10. Defining the Messages
  11. The Arduino Part
  12. The Java Application
  13. Finished Setup
  14. Tip: Checking the Network Packages Between Arduino and Raspberry Pi
  15. Just a Thought - Beware of the PAF

Conclusion

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $14 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub