Getting started with Java on the Raspberry Pi
This book is 47% complete
Last updated on 2019-11-19
About the Book
When I first managed to blink a 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 a lot of tips and tricks to become or be a better developer. And above all many simple examples on these and even more other topics:
- The magic of Bits and Bytes and solving the confusing of Java signed values with the help of a 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, motors, relais boards and many more.
- Spring applications so you can interact with your Pi via web interfaces.
- How to setup a queue so you can send and receive messages to and from Arduino boards or other Pi's.
- 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 I which would have been bundled at the time I started my own 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 you can extend your knowledge and control the world around you with simple and inexpensive components.
Chapter 1: Introduction
- About me
Sources and scripts used in this book
- Where to find them
- Get the sources
- Styling used in the book
Read the README!
- What’s next?
- Thanks to…
Chapter 2: Tools used in this book
Software tools on the PC
- Integrated development environment aka IDE
- Wiring diagrams
- Schematic drawings
- Prepare the Pi
- Connections between Pi and breadboard
- Extra software on the Pi
- Electronic kit with Arduino board
- LED strips
- Software tools on the PC
Chapter 3: About Java
- Java files versus byte code
JVM versus JRE versus JDK
- JVM = Java Virtual Machine
- JRE = Java Runtime Environment
- JDK = Java Development Kit
- What has changed in between Java 11 versus 8
- What’s next after Java 11?
- Azul Zing and Zulu
- BellSoft Liberica
- Interview with Alexander Belokrylov
Install Java on a Pi
- Raspbian (Buster) has Java 11 pre-installed
- Downloading and testing BellSoft Liberica JDK
- HelloWorld! Running a single file Java application
Chapter 4: Choosing an IDE
Comparing some possibilities
- Visual Studio Code (VSC)
- Program on the Pi 4
- Interview with the people behind Visual Studio Code
- Comparing some possibilities
Chapter 5: Raspberry Pi pinning
Raspberry Pi types
- Major versions
- Board versions
Headers and pins
- Pin types
- Pin functions
- Header types
Different pinning numberings
- Header pin numbers
- WiringPi numbers
- BCM numbers
- PigPio numbers
- Raspberry Pi types
Chapter 6: What is Maven?
- On Windows PC
- On Raspberry Pi
Generate a new Maven project
- Project structure
- A minimal pom.xml example
- Adding logging
- Install Maven
Chapter 7: JavaFX
Sample libraries to extend JavaFX
- Interview met Gerrit Grunwald
Minimal JavaFX 11 sample application
- Add new archetypes to Maven
- Creating an empty application
- Running the empty application from Visual Studio Code
- Building the application for the Pi
- Running the minimal JavaFX 11 application on the Pi
Example 1: TilesFX dashboard
- And now with Java
- And now we start with building our first JavaFX application
- Start a Java application when the Pi starts up
Example 2: Build a UI with FXML
- Scene builder
- Just a thought - Beware of the PAF
Chapter 8: Bits and bytes
- Convert bits to a numeric and hex value
- Calculate a byte value
Value ranges in Java
- Difference between Byte, Short, Integer and Long
- Minimum and maximum values in Java
- Signed versus unsigned
What can we do with this?
- Web colors
- Controlling a numeric segment display
Chapter 9: PI4J
- Digital output example
- Digital input example
- I2C example
- Infrared receiver
- Sample applications
Chapter 10: ROBO4J
- Controlling robot motors
- Sample applications
Chapter 11: Spring
- What is Spring boot?
- What is Spring initializr?
Example 1: Minimal web server on the Pi
- Start from the Initializr project and modify pom.xml
- Swagger config
- Image controller
Example 2: REST webservice on the Pi to toggle a LED
- Example 3: Database REST webservice to store IoT data on Pi
Chapter 12: Message Queues
- Publish/subscribe message flow
- Some example use cases
Using Mosquitto on the Pi
- Testing Mosquitto on the Pi
Example 1: Share data between Pi and PC
- Modifying the pom and module-info
- Connecting and publishing to Mosquitto
- Subscribing to Mosquitto
- The user interface
Example 2: Control Arduino from JavaFX via Mosquitto
- Defining the messages
- The Arduino part
- The Java application
- The finished setup
- Tip: Checking the network packages between Arduino and Pi
The Leanpub 45-day 100% Happiness Guarantee
Within 45 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms
Free Updates. Free App. 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), EPUB (for phones and tablets), MOBI (for Kindle) and in the free Leanpub App (for Mac, Windows, iOS and Android). 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.