Java for Embedded Systems: Advantages and Disadvantages

By Kaique Mancoso

Digital Marketer

TotalCross

February 02, 2021

Story

Java for Embedded Systems: Advantages and Disadvantages
(Image Courtesy of TotalCross)

An alternative that guarantees a low footprint (5 MB) and high performance for embedded systems.

Embedded systems like IoT, UI/UX, and AI are getting more and more complex every day. Products that in the past had only one or two functions, now provide many more utilities for the users, demanding a reflection of the experience to be provided by the User Interface. The Internet of Things is changing the way we deal with hardware, guaranteeing a connected, automated, and even smarter daily routine. Java is one of the most used programming languages, especially due to the fact that it’s easy to develop and cross-platform with. But, Java hasn’t been widely adopted in the development of embedded systems yet. In fact, C/C++ are still the most popular programming languages for embedded systems. Around 80% of embedded system projects are written with C/C++, but it will not be this way in the future. New languages may be adopted to meet market growth. Building projects with C/C++ is time-consuming and it will be very hard to find or train new professionals in C/C++. The purpose of this article is to show the main advantages of using Java for embedded systems development, and which are the disadvantages of this language (and also, suggesting ways to deal with and solve these disadvantages).

IoT and Embedded systems vs Java

Over the years, the number of professionals involved in embedded systems development has grown considerably. Of course, there is a huge difference between this kind of professional and the number of people working on application development for desktops and mobile. But, according to IC Insights, the sales of MPU for embedded devices will be on the same level as smartphones in three years.

Machines in general, have been equipped with a real technological arsenal. Products around us like cars and home appliances have been created with the capabilities to respond to different events and requirements of human needs. Within this context, IoT represents not a future trend, but something that is happening right now. This can also be seen in industrial settings. Industrial automation is requesting more connectivity, data analysis, and of course, new dashboards.

Considering all of this, it’s necessary to have an eye on future expectations. Despite the fact C and C++ require less memory and CPU cycles, Java should be considered as a better option for embedded systems because it’s one of the most organized programming languages which is ideal for big projects. Java has ideal characteristics for the embedded systems environment that include portability, code reuse, reliability, security, WEB, and connection with other embedded systems. To provide what the embedded world will demand (and is already demanding) it’s important to use a high level language like Java. Besides, there are a lot of Java developers in the world, and the migration to embedded systems should not be a problem for them.

Advantages of using Java on embedded systems

Developing an application with Java for embedded devices, besides the best language quality, guarantees a reduction of time and cost applied to the project creation, thanks to the variety of uses and existing support. So, let’s see some other reasons why you should use Java for embedded systems:

  • Time to market is important, providing less development time: Java has ideal memory management and it’s easier to detect errors (and fix them);

  • It is recommended for GUI projects with over 5 screens;

  • Sturdiness from the first version on (thanks to package concepts, design patterns and SOLID principles);

  • Simplicity;

  • Portability to different CPU or operating systems (no need for code rewriting);

  • Security, with support for encrypting sensitive data;

  • A large arsenal of OS-independent libraries;

  • Debuggable on the desktop and remotely;

  • Best compromise in terms of high level language and high performance (depends on the Virtual Machine used);

It seems perfect! But (like everything in the world) there are some cons too. Let’s see the challenges of Java for embedded systems.

Disadvantages of using Java for embedded systems

There are a lot of good reasons for choosing Java. But, there are three main disadvantages of using Java on embedded systems:

  • Java is quite verbose;

  • It is complex and vast (217 packages with 4240 classes);
  • Low performance.

Even Oracle themselves created the Java SE Embedded to solve these kinds of problems, with a Virtual Machine optimized for embedded devices. But, this wasn't enough for a large number of projects that targeted low-end devices.

This concern has been the main barrier for the entry of Java to embedded systems. But the good news is that there are some new technologies aimed at solving all these problems.

Low footprint and high performance for embedded systems

To achieve this goal it’s necessary to find an alternative to the full Java and Java Virtual Machine. TotalCross is an interesting framework to look at in this case.

TotalCross is an SDK for embedded systems and uses its own virtual machine, called the TotalCross Virtual Machine (TCVM). Instead of JVM which is stack-based, TCVM is a register-based virtual machine. This makes a huge difference in running time, because it reduces the number of instructions loaded. As you can see in the following example, a simple operation loads four instructions on JVM and only one when being run on TCVM. 

Besides TCVM, an optimized bytecode called TotalCross bytecode has been created based on statistical research to identify the most used functions that have a larger impact on performance. As well as the pressure of these functions to reduce the number of instructions, this optimized bytecode also ensures a low footprint, as it uses a subset of Java called Nano Java which has only 86 packages and 1184 classes (¼ of full Java).

TotalCross does not use all of the Java architecture, but only what is necessary for embedded application development. All of these characteristics deliver a 5MB footprint and high performance to embedded systems.

Conclusion

There are more advantages than disadvantages of using Java on embedded systems, especially because of the quality of the code and the large number of people already able to program with Java. It is especially important to have the Java community inside the embedded systems universe, because it is the third biggest in the programming world. But, as we saw, the footprint and the performance can affect the project results. Therefore, it is recommended to have an alternative that is capable of breaking down these barriers, like the TotalCross framework. With it, it is possible to enjoy all the advantages of Java and still guarantee a low footprint and high performance for embedded systems.

Featured Companies