If you are unfamiliar with the history of the Java programming language, you may not know that before it came to dominate as the language of choice for server-side applications, and even before its splash as a way to make Web pages more dynamic, it started as a language for embedded devices.  Now well established and mature, it is an excellent choice for embedded software as part of an Internet of Things (IoT) device.  And Renesas has partnered with Micrium and IS2T in order to make that choice available on the RX family of microcontrollers.  You may be surprised at the minimal overhead; the Java virtual machine takes less than 30 KB of Flash memory and less than 1.5 KB of RAM at runtime.  The startup time on a 120 MHz CPU is less than 2 ms.

Why are so many embedded software developers turning to Java over C?  There are a number of reasons, including faster time-to-market and tapping into the large pool of Java developers coming from other platforms, but I would like to talk about two reasons in more depth.

The first I’ll mention has to do with memory management.  In C, you must follow very different rules for variables on the stack versus those that live on the heap.  For instance, if a C function is going to return a pointer, it had better not be pointing at the stack!  And while calling free() on a pointer to a stack variable will probably cause your program to crash, forgetting to call free() on a heap allocation is the definition of a memory leak.  Java takes care of both of these issues by performing automatic memory management.  Simply drop references to unused objects, and the Java Virtual Machine (JVM) will deallocate the memory as needed.  And the distinction between stack and heap-allocated objects is completely taken care of by the compiler and JVM.

The second benefit I want to highlight is runtime safety.  Object references and array indexes are kept entirely separate, and it is impossible to use an invalid index on an array.  This eliminates large swaths of security vulnerabilities, which is an important consideration for IoT devices.

 

You can download a free 30-day trial version of MicroEJ Java Kickstart Platform for the Renesas RX63N based YLCDRX63N board and Micrium μC/COS-III and join the wonderful world of Java!