Java's creators had a vision for the language to be “write once, run anywhere," and their success couldn’t be more obvious than in the embedded world.
Being able to write just one version of a Java program and run close to the same binaries everywhere is a big draw for teams that create software for small devices and hidden computers. In many cases, these developers don't know much about the CPU that will run in the final shipping product, and they don't need to.
Java's flexibility to run anywhere also helps product teams in the long term, because the second, third, or fourth generation of a product might run on different chips. The software can usually be adapted with little or no additional coding.
Today, numerous Java frameworks are used to create embedded Java applications. Some are general tools intended to be used in many types of machines. They’re often the best starting point for teams creating new applications.
Other frameworks were developed for a specific device or family of devices. These may include both a programming foundation and features that support the devices or other products your app will run on. The most common example of this type of embedded Java framework may be Android, which developers use to create apps for Android phones, Chromebooks, and other devices like televisions.
Here are eight great embedded Java frameworks. Each of them leverages the stability and breadth of the Java platform and third-party libraries for small devices and hidden computers. These frameworks adapt traditional Java techniques and approaches to run faster and lighter in the embedded market.
Android is likely the most well-known Java embedded framework. It began as a foundation for creating apps for the phones that Google was building to compete with Apple. Much of the original code base was open sourced, and now many other types of devices (not just phones) support Android apps.
Google’s ChromeOS, used in Chromebooks, is just one example. Dozens of small boxes bring Android apps to big, flat screens for the living room.
Writing Android apps is a simple way to target all of these devices. It also allows device creators to open up their products to third-party developers.
Some developers work with just the basic Android libraries, which are more than sufficient for many programs. Others use frameworks that sit on top of Android. Some of the most popular are Ionic, Flutter, and Framework7. A common feature lets developers repurpose the design for other platforms like iOS. Flutter, for instance, targets six different platforms.
Java Embedded Framework
Java Embedded Framework makes it simpler for developers to write high-level Java code that speaks to the interfaces that are common in embedded systems.
Popular examples are Raspberry Pi and Orange Pi. With this framework, you do not need to master the low-level programming required to communicate with hardware interfaces like SPI, I2C, Serial, GPIO, or One Wire. The framework's developers have already handled most of that for you.
Java Embedded Framework is broken into several major modules. The main module connects directly to the Linux OS layer that controls the board. It simplifies using pure Java to connect to many tasks on the operating system layer. There are also drivers for the major hardware components commonly found on these small boards.
Oracle Event Processing
One of the jobs for an embedded device is to capture data. Factory floors, for instance, rely on embedded machines to track production and watch for anomalies. The Oracle Event Processing framework is a lightweight version of the Oracle Event Driven Server that enables the devices to capture events, filter them, and pass them on as needed.
Some of the configuration syntax is borrowed from SQL, which makes it relatively easy to pick up. The framework's event processing model can also dig into the event stream to look for correlations and other patterns in the data.
If a job requires programming an embedded device to respond to RESTful events, Jersey is a good option. It’s optimised for juggling the JSON packets that are coming and going by extending the JAX-RS toolkit. Architects like this solution because it can be one of the best ways to automate communication with the device.
Jersey offers a few extras, including the ability to “chunk” responses. This means storing data and then sending it in one big chunk. Chunking is especially useful for devices that are not always connected to the internet. It’s also useful for reducing the load on any central server that is tasked with communicating with many devices.
Many people think of Vert.x as a framework for building full-featured web applications. What's nice is that it's broken into modules, and you don’t have to use all of them. The core of Vert.x contains most of the important code for writing services that interact with the world and the machine.
Anyone creating a basic tool can rely on the Vert.x framework's networking and file system protocols to set up streams that juggle incoming and outgoing requests.
Some of the Vert.x modules may be ideal for embedded tasks. The OpenAPI and API Service libraries, for example, perform many of the chores for supporting an API. The GraphQL library folds in the routines necessary for supporting GraphQL calls. These libraries focus mainly on building out web applications and web services, but they can also be leveraged for handling simpler communication.
Any application that needs a robust networking layer can use Apache Mina to juggle some of the different NDP (Neighbor Discovery Protocol) or TCP connections in a secure and reliable way.
The code is built on top of the new IO classes (Java NIO) so that developers can treat the data that’s coming or going in a more abstract fashion. The code for it is largely event-driven, sparing developers the need to mind the network interface.
Some embedded processors are wrapped in additional security layers to help with sensitive data such as the details of financial transactions. Oracle's Java Card supports multiple applications running inside such secure enclaves like tamper-resistant chips. These CPUs are often slower and come with less memory and Java Card’s framework is stripped down to run smoothly with fewer resources.
What about Java web frameworks?
While this article highlights frameworks designed for embedded machines, the reality is that more and more developers are creating web applications for embedded devices.
Smaller devices may be less powerful, but they often have enough RAM and CPU power to run a web server application for a few clients. An application that is not intended for a billion users on the open internet can run just fine in an embedded system.
This is often a good solution because it lets users connect to the device through a web application. Developers can leverage all the standard features of a basic website.
Many of the popular web application frameworks work remarkably well on small machines. This is, in part, due to the push to shrink and simplify the server side of Java web applications. Newer, lightweight frameworks like Spring Boot, Vert.x, and Vaadin (also see Hilla), are all reliable choices. Some embedded developers even get by with older, heavier frameworks like Spring, Struts, or JavaServer Faces.
All of these frameworks date from the years when servers were much less powerful. They can work well for scenarios where one user needs to interact with the software and the embedded device is relatively powerful.
Using standard Java for embedded apps
Some developers don’t need to use an embedded framework because they get the libraries and features they need from a standard Java version. Java Micro Edition (JME) comes in several versions and some are explicitly designed for embedded systems. They provide important Java libraries, such as an OAuth library for authentication and a JSON library for parsing and composing messages. In some cases, that may be enough.
Developers with larger, more powerful boards may even use Java Standard Edition for embedded applications on small devices. Oracle Java SE Embedded is a standard version of Java tuned for the embedded world.
Oracle supports many different types of devices by making standard binaries available. For instance, Raspberry Pi and a few other small embedded systems are prebuilt. Oracle also supports important market segments such as phones and televisions.
For basic embedded Java development projects, a standard download from Oracle could offer everything you need.