Getting started with Java on the Raspberry Pi - UPDATE 2024
$9.99
Minimum price
$19.99
Suggested price

Getting started with Java on the Raspberry Pi - UPDATE 2024

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

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 includes a lot of info and history about Java itself and how to install it on the Raspberry Pi. Also, there are a lot of tips and tricks to become or be 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. This chapter was further extended in 2023 to illustrate how easy it is to control electronics with Pi4J V.2 in combination with single-file applications with JBang.
  • Spring applications so you can interact with your Pi via web interfaces.
  • How to set up a queue to send and receive messages to and from Arduino boards or other Pi's.
  • Interviews with some of my heroes: Karen Mouws (STEM and diversity), Alexander Belokrylov (BellSoft Liberica JDK), Trisha Gee (IntelliJ IDEA), Xiaokai He (Visual Studio Code), Jakob Jenkov (tutorials.jenkov.com), Johan Vos (OpenJFX, JavaFX, and GluonHQ), Robert Savage (Pi4J), Gerrit Grunwald (JavaFX, TilesFX), Mark Heckler (Spring), Vlad Mihalcea (JPA, Hibernate), Simon Ritter (Azul), Geertjan Wielenga (Azul and Foojay), Max Rydahl Andersen (JBang), 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.

  • Share this book

  • Categories

    • Raspberry Pi
    • Embedded Systems
    • Java
    • Messaging
    • Home Automation
    • Internet of Things
    • Software
    • DIY
    • Computers and Programming
  • Feedback

    Email the Author(s)

About the Author

Frank Delporte
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...

Table of Contents

    • 1:Chapter 1: Introduction
      • 1.1:Content overview
      • 1.2:Content updates
        • 1.2.1:Updates during 2022
        • 1.2.2:Updates during 2023
        • 1.2.3:Updates during 2024
      • 1.3:About me
      • 1.4:Sources and scripts used in this book
        • 1.4.1:Where to find them
        • 1.4.2:Get the sources
      • 1.5:The styling used in the book
      • 1.6:Read the README!
        • 1.6.1:Guidelines
        • 1.6.2:Example
        • 1.6.3:What’s next?
      • 1.7:Thanks to…
    • 2:Chapter 2: Tools and hardware used in this book
      • 2.1:Raspberry Pi
        • 2.1.1:Prepare the Pi
        • 2.1.2:Connections between Pi and breadboard
      • 2.2:Software tools on the Pi
        • 2.2.1:Linux commands crash course
        • 2.2.2:Firefox
        • 2.2.3:VNC server
        • 2.2.4:Enable SSH on the Raspberry Pi
      • 2.3:Free software tools on PC
        • 2.3.1:Integrated Development Environment aka IDE
        • 2.3.2:Remote connection to a Raspberry Pi (SSH)
        • 2.3.3:Wiring diagrams
        • 2.3.4:Schematic drawings
      • 2.4:Hardware components
        • 2.4.1:Resistors
        • 2.4.2:LEDs
        • 2.4.3:RGB-LED
        • 2.4.4:LED strips
      • 2.5:Shopping list
        • 2.5.1:Raspberry Pi
        • 2.5.2:Electronics
    • 3:Just a thought: Learn by educating
      • 3.1:Interview with Karen Mouws
    • 4:Chapter 3: Choosing an IDE
      • 4.1:IntelliJ IDEA
        • 4.1.1:Using IntelliJ IDEA with the example projects
      • 4.2:Interview with Trisha Gee
      • 4.3:Visual Studio Code (VSC)
        • 4.3.1:VSC on Raspberry Pi OS 32-bit
        • 4.3.2:VSC on Raspberry Pi OS 64-bit
        • 4.3.3:VSCodium the free non-tracking alternative to VSC
        • 4.3.4:Java development with Visual Studio Code
        • 4.3.5:Using Visual Studio Code on the PC with code on the Pi
      • 4.4:Interview with Xiaokai He
    • 5:Chapter 4: About Java
      • 5.1:History
      • 5.2:Java files versus byte code
      • 5.3:JVM versus JRE versus JDK
        • 5.3.1:JVM = Java Virtual Machine
        • 5.3.2:JRE = Java Runtime Environment
        • 5.3.3:JDK = Java Development Kit
      • 5.4:Version history
      • 5.5:JDK providers
        • 5.5.1:Oracle
        • 5.5.2:Temurin
        • 5.5.3:Azul Zulu
        • 5.5.4:Interview with Simon Ritter
        • 5.5.5:BellSoft Liberica
        • 5.5.6:Interview with Alexander Belokrylov
      • 5.6:Installing the Java JDK
        • 5.6.1:Install Java JDK on a Windows PC
        • 5.6.2:Install Java JDK on a Linux PC or macOS with SDKMAN
        • 5.6.3:Install Java JDK on a Raspberry Pi
      • 5.7:Some of the changes between Java versions
        • 5.7.1:Changes between Java 8 and 11
        • 5.7.2:What’s next after Java 11?
      • 5.8:Java crash course
        • 5.8.1:HelloWorld! Running a single-file Java-application
        • 5.8.2:Using the start-up arguments
        • 5.8.3:Working with numbers
        • 5.8.4:If, Then, Else
        • 5.8.5:Enum and Switch
        • 5.8.6:Using methods
        • 5.8.7:Using objects
        • 5.8.8:Reading a text file
        • 5.8.9:Using streams
        • 5.8.10:What’s next?
      • 5.9:Interview with Jakob Jenkov
      • 5.10:Foojay.io
        • 5.10.1:Java Version Almanac
        • 5.10.2:OpenJDK Update Release Details
        • 5.10.3:OpenJDK Command Line Arguments
        • 5.10.4:Foojay Today
        • 5.10.5:Comprehensive Search
        • 5.10.6:Foojay Podcasts
        • 5.10.7:Interview with Geertjan Wielenga
    • 6:Chapter 5: Raspberry Pi pinning
      • 6.1:Raspberry Pi types
        • 6.1.1:Models
        • 6.1.2:Major versions
        • 6.1.3:Board versions
      • 6.2:Pin types
        • 6.2.1:Power and ground
        • 6.2.2:Digital GPIO
      • 6.3:Pin functions
        • 6.3.1:Universal Asynchronous Receiver and Transmitter (UART - Serial)
        • 6.3.2:General Purpose Clock (GPCLK)
        • 6.3.3:Inter Integrated Circuit (I²C)
        • 6.3.4:Serial Peripheral Interface (SPI)
        • 6.3.5:Pulse-Width Modulation (PWM)
      • 6.4:Header types
        • 6.4.1:40-pin header
        • 6.4.2:26-pin header - Type 1 and 2
        • 6.4.3:8-pin header
      • 6.5:Different pinning numbering schemes
        • 6.5.1:Board (pin) number
        • 6.5.2:BCM number
        • 6.5.3:WiringPi number
    • 7:Chapter 6: What is Maven?
      • 7.1:Install Maven
        • 7.1.1:On Windows PC
        • 7.1.2:On Raspberry Pi
      • 7.2:Generate a new Maven project
        • 7.2.1:Project structure
        • 7.2.2:A minimal pom.xml example
      • 7.3:Maven pom-files used in this book
      • 7.4:Add application logging with Maven and log4j
    • 8:Just a thought: Abbreviations
    • 9:Chapter 7: About JavaFX
      • 9.1:History
      • 9.2:Interview with Johan Vos
      • 9.3:Sample libraries to extend JavaFX
        • 9.3.1:TilesFX
        • 9.3.2:FXRibbon
        • 9.3.3:ControlsFX
        • 9.3.4:PickerFX
      • 9.4:Interview with Gerrit Grunwald
      • 9.5:Minimal JavaFX 11 sample application
        • 9.5.1:Add new archetypes to Maven
        • 9.5.2:Creating an empty application
        • 9.5.3:Running the empty application from Visual Studio Code
        • 9.5.4:Running the application on the Pi
      • 9.6:Example 1: TilesFX dashboard
        • 9.6.1:Wiring and testing in terminal
        • 9.6.2:Blink an LED with Java
        • 9.6.3:Building our first JavaFX application
        • 9.6.4:Run the application on PC
        • 9.6.5:Run the application on the Pi
        • 9.6.6:Conclusion
      • 9.7:Start a Java application when the Pi starts up
      • 9.8:Disable screensaver
      • 9.9:Example 2: Interact with an I²C relay board
        • 9.9.1:Enable and test I²C
        • 9.9.2:Coding the I²C controller application
        • 9.9.3:Running the relay controller on the Pi
      • 9.10:Example 3: Build a UI with FXML
        • 9.10.1:Generate an empty FXML project as a starting point
        • 9.10.2:Scene Builder
    • 10:Just a thought - Beware of the PAF
    • 11:Chapter 8: Bits and bytes
      • 11.1:Convert bits to a numeric and hex value
      • 11.2:Calculate a byte value
      • 11.3:Value ranges in Java
        • 11.3.1:Difference between Byte, Short, Integer and Long
        • 11.3.2:Minimum and maximum values in Java
        • 11.3.3:Signed versus unsigned
        • 11.3.4:Conclusion
      • 11.4:What can we do with this?
        • 11.4.1:Web colors
        • 11.4.2:Controlling a numeric segment display
    • 12:Chapter 9: Pi4J
      • 12.1:Interview with Robert Savage
      • 12.2:Pi4J V.1
        • 12.2.1:Installation
        • 12.2.2:Programming with Pi4J
        • 12.2.3:Digital GPIO input and output examples
        • 12.2.4:PWM example
        • 12.2.5:SPI example with MAX7219 and 8x8 LED-matrix
        • 12.2.6:Serial communication example with an Arduino
        • 12.2.7:LCD-display with the weather forecast
      • 12.3:Pi4J V.2
        • 12.3.1:Minimal V2 example with a LED and button
        • 12.3.2:More Pi4J V2 examples
      • 12.4:Pi4J V.2 with JBang
        • 12.4.1:Interview with Max Rydahl Andersen
        • 12.4.2:Prepare a Raspberry Pi
        • 12.4.3:Install JBang
        • 12.4.4:Minimal JBang example
        • 12.4.5:How to use dependencies with JBang
        • 12.4.6:Minimal Pi4J example with JBang
        • 12.4.7:JBang, Pi4J, and an SPI 8x8 LED Matrix
        • 12.4.8:JBang, Pi4J, and a BME280 sensor
        • 12.4.9:JBang and Pixelblaze Output Expander
      • 12.5:Building a Game with Pi4J V.2 and FXGL
        • 12.5.1:What is FXGL?
        • 12.5.2:Interview with Almas Baim
        • 12.5.3:Joystick Wiring
        • 12.5.4:Game Application Code
        • 12.5.5:Running the game on Raspberry Pi
    • 13:Just a thought: Switching social
    • 14:Chapter 10: Spring
      • 14.1:What is Spring Boot?
      • 14.2:What is Spring Initializr?
      • 14.3:Interview with Mark Heckler
      • 14.4:Example 1: Minimal web server on the Pi
        • 14.4.1:Start from the Initializr project and modify pom.xml
        • 14.4.2:Application properties
        • 14.4.3:Image controller
        • 14.4.4:Swagger config
        • 14.4.5:Run on the Pi
        • 14.4.6:Conclusion
      • 14.5:Example 2: Database REST-service for IoT data on Pi
        • 14.5.1:pom.xml settings
        • 14.5.2:Creating the database entities
        • 14.5.3:Storing data in the database
        • 14.5.4:Adding the REST-services
        • 14.5.5:Adding Swagger
        • 14.5.6:Running the application and using the REST-services
        • 14.5.7:Configuration to run on the Pi
        • 14.5.8:Conclusion
      • 14.6:Interview with Vlad Mihalcea
      • 14.7:Example 3: REST-service on the Pi to toggle an LED
        • 14.7.1:Info REST-controller
        • 14.7.2:GPIO Manager
        • 14.7.3:GPIO REST-controller
        • 14.7.4:Running the application on a Pi
        • 14.7.5:Conclusion
      • 14.8:Example 4: Reactive data
        • 14.8.1:The code
        • 14.8.2:Running the streaming application on the Pi
        • 14.8.3:Conclusion
    • 15:Just a thought: Impostor Syndrome
    • 16:Chapter 11: Message Queues
      • 16.1:Using Mosquitto on the Pi
        • 16.1.1:Installation
        • 16.1.2:Testing Mosquitto on the Pi
      • 16.2:Example 1: Share data between Pi and PC
        • 16.2.1:Modifying the pom and module-info
        • 16.2.2:Connecting and publishing to Mosquitto
        • 16.2.3:Subscribing to Mosquitto
        • 16.2.4:The user interface
      • 16.3:Example 2: Control Arduino from JavaFX via Mosquitto
        • 16.3.1:Defining the messages
        • 16.3.2:The Arduino part
        • 16.3.3:The Java application
        • 16.3.4:The finished setup
        • 16.3.5:Tip: Checking the network packages between Arduino and Pi
    • 17: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 earnedover $14 millionwriting, 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