Friday May 15, 2015

Using Line User Interface with Oracle Java ME Embedded 8.1 on STMicroelectronics Evaluation board

Oracle Java ME Embedded 8.1 Developers Preview for ST Micro Evaluation board has been recently released. 

As I mentioned in my previous post, one of the release additions is a Line User Interface (LUI) API hardware implementation. LUI is an optional API of MEEP (JSR 361), which enables rendering text information on a display. In Java ME Embedded 8.0 this functionality was supported only by Java ME SDK Emulator and now it is possible to use a hardware display to implement a simple user interaction in Java ME Embedded applications. 

Java ME SDK 8.1 update includes a very good LUI sample. The sample is an on-screen text menu navigated by a built-in joystick. The menu has 12 items, several nested items, and a status line reflecting a current user choice.  Code of the sample is accompanied very detailed comments, which can definitely helps start developing interactive applications very fast.

Below is a basic example that demonstrates the use of the built-in screen on STM32429I-EVAL board with Java ME Embedded and LUI API.

 Happy Java coding for embedded.

import java.util.Iterator;
import javax.microedition.lui.Display;
import javax.microedition.lui.DisplayColor;
import javax.microedition.lui.DisplayListener;
import javax.microedition.midlet.MIDlet;

public class LUIDemo extends MIDlet implements DisplayListener {

    public void startApp() {
        // Get Display instance and configure it
        Iterator<Display> displays = Display.getDisplays(false);
        Display myDisplay =;
        // Assign a state change listner to Display instance
        myDisplay.addDisplayListener((DisplayListener) this);
        //as soon as the hardware display will be assigned to myDisplay instance
        //hardwareStateChanged method will be invoked with newState = true 
        synchronized (myDisplay) {
            try {
                // Assign hadware display to myDisplay 
                // Assigning display may take some time,
                // so that we need to wait the operation acomplishement 
                // Now myDisplay has HW display assigned and we can use it
            } catch (InterruptedException ex) {
        //Display.setText is overloaded method. 
        //In the example below the text "Hello world" is blinking.
        myDisplay.setText(0, "Hello world", true, false);
        myDisplay.setText(1, "I love programming Java ME Embedded on STM32429EVAL");

    public void destroyApp(boolean unconditional) {

    // hardwareStateChanged method is invoked as the hardware display is assigned or unassigned
    public void hardwareStateChanged(Display d, boolean newState) {
        //Setting up assigned hardware display
        d.setLightingColor(new DisplayColor(0xFF, 0, 0));
        d.setCurrentTextColor(new DisplayColor(0, 0, 0xFF));
        d.setBackgroundColor(new DisplayColor(0, 0, 0));
        // notify all threads are waiting for Display Object
        synchronized (d) {

    public void displayAdded(Display d) {

    public void displayRemoved(Display d) {

Friday May 08, 2015

Oracle Java ME Embedded 8.1 released with support of STMicroelectronics STM32F4 micro controller

Oracle Java ME Embedded 8.1 Developer Preview for STM32429I-EVAL has been released today. With this release, the STM32F4 series of micro controllers is joining the family of platforms supported by Java ME Embedded. 
ST Micro produces widely used and very popular high-performance MCUs with the STM32F4 core, which is based on the ARM Cortex-M4 architecture. The detailed information can be founded at STM web.  The Java ME 8.1 Embedded STM port release enables developers to run feature-rich Java ME Embedded applications on the STMicroelectronics STM32429I-EVAL developer evaluation board. 

The Java ME 8.1 follow-up release for STM has full CLDC 8 support, networking, storage, and peripheral I/O support, including GPIO, I2C, SPI, ADC, UART, and other interfaces. The interesting particularity of the release is the implementation of this port on top of ARM Cortex Microcontroller Software Interface Standard (CMSIS), which will allow Oracle and its partners to make feature porting easier and faster.

With this release, developers are able to access on-board screen with the simple Line User Interface (LUI) API. Java ME SDK Update center is distributing an update package with a great example of developing a text menu operated by on-board joystick. After its installation, a LUI sample can be found at your local drive:

Do not forget to update Java ME 8.1 SDK by navigating to NetBeans or Eclipse menu Tools -> Java ME -> Java ME SDK Update Center and installing the STM32429I-EVAL SDK Update. After applying this update, you will be able to work with STM32429I-EVAL as with any other ME SDK supported board.

Feel free to ask any questions and provide your feedback at our forum:

Wednesday Feb 04, 2015

January-February Java Magazine issued

Recently the first issue of Java Magazine 2015 have been released. If you are still not a subscriber, blame on you. It is absolutely free and as publisher admitted: "Java Magazine is an essential source of knowledge about Java technology, the Java programming language, and Java-based applications for people who rely on them in their professional careers, or who aspire to.” Subscribe here:

This issue contain an article "Embedded: Get Started with Oracle Java ME Embedded 8 on Microcontrollers”, which is giving to readers a detailed explanation on how to develop Java ME applications for micro controllers and connect to peripheral by DIO API. Significant part of the article is describing how to connect to I2C sensor using it’s datasheet.

Happy reading, and just in case you have any question I welcome you to our forum

Wednesday Nov 19, 2014

Java ME Embedded 8.1 brings Java to ARM Cortex M4 and provides Eclipse users with tools for embedded development

A couple days ago, Java ME Embedded 8.1 was released. The new version of the Java ME Embedded platform has two significant enhancements. First, it works on ARM Cortex M4 with very limited RAM size by delivering a port for Freescale K64F. Second, it provides Eclipse IDE support in Java ME SDK. The link to the release page:

FRDM-K64F is based on  MK64FN1M0VLL12 MCU (120 MHz, 1 MB flash memory, 256 KB RAM, low-power, crystal-less USB, and 100 Low profile Quad Flat Package (LQFP)). It is has a form-factor of Arduino™ R3 pin layout. The FRDM-K64F goes with a lot of peripherals to enable rapid prototyping. In addition to UART, I2C, SPI, and GPIO interfaces on board, it has 3 LEDs and 2 switches which are accessible from Java Runtime. Another helpful device that is integrated into K64F is accelerometer-magnetometer with I2C interface (FXOS8700Q). You can easily access it from your Java application and create a compass application, for instance. Find the code example below the post..

Java ME SDK 8.1 brings smooth experience of Java Embedded developers to the Eclipse world. Java ME SDK plugin for Eclipse is based on the recently released Mobile Tools for Java TM (MTJ) 2.0 which had been done with significant efforts of Oracle's engineers. Now, all impressive features of Java ME SDK, such as on-device debugging, memory and network monitors, CPU profiling, and memory profiling are available in Eclipse. To install it, you need just to go the OTN web, download and install Java ME SDK with Eclipse plugin

If you have any questions or suggestions, please speak up at our forum:
The best source of information about Java ME Embedded is Java ME Documentation portal:

How to get a device ID from FXOS78700Q on K64F:
public class FXOS8700Q extends MIDlet {

    private I2CDevice fxos8700q;

    final int FXOS8700Q_STATUS = 0x00;
    final int FXOS8700Q_OUT_X_MSB = 0x01;
    final int FXOS8700Q_OUT_Y_MSB = 0x03;
    final int FXOS8700Q_OUT_Z_MSB = 0x05;
    final int FXOS8700Q_M_OUT_X_MSB = 0x33;
    final int FXOS8700Q_M_OUT_Y_MSB = 0x35;
    final int FXOS8700Q_M_OUT_Z_MSB = 0x37;
    final int FXOS8700Q_WHOAMI = 0x0D;
    final int FXOS8700Q_XYZ_DATA_CFG = 0x0E;
    final int FXOS8700Q_CTRL_REG1 = 0x2A;
    final int FXOS8700Q_M_CTRL_REG1 = 0x5B;
    final int FXOS8700Q_M_CTRL_REG2 = 0x5C;
    final int FXOS8700Q_WHOAMI_VAL = 0xC7;
    final int UINT14_MAX = 16383;

    public void startApp() {
        ByteBuffer buffer = ByteBuffer.allocateDirect(1);
        try {
            fxos8700q =, I2CDevice.class);
            buffer = read(FXOS8700Q_WHOAMI, 1, 1);
        } catch (IOException ex) {
        String id = String.format("%8s", Integer.toBinaryString(buffer.get(0) & 0xFF)).replace(' ', '0');

    public void destroyApp(boolean unconditional) {

    void write(int address, int addressSize, ByteBuffer data) throws IOException {
        fxos8700q.write(address, addressSize, data);

    ByteBuffer read(int address, int addressSize, int bytesToRead) throws IOException {
        ByteBuffer buffer = ByteBuffer.allocateDirect(bytesToRead);
        fxos8700q.begin();, addressSize, buffer);
        return buffer;

Monday Nov 17, 2014

Mobile Tools for Java™ (MTJ) 2.0 plugin for Eclipse IDE released

I proud to announce that a new version of MTJ plugin for Eclipse have recently been released with a significant contribution of Oracle's engineers. Mobile Tools for Java TM (MTJ) 2.0 release is making MTJ plugin IoT ready by supporting Java ME Embedded 8 platform. Oracle Java ME Embedded 8 is Java TM Runtime client optimized for ARM based micro controllers and other constrained devices. Now MTJ 2.0 provides a support for CLDC 1.8 configuration (JSR 360), MEEP 8.0 profile (JSR 361) support, MEEP 8.0 profile (JSR 361), better IMP-NG profile (JSR 228) support. MEEP 8.0 permissions mechanism was significantly changed and looks similar to Java SE, MTJ 2.0 supports MEEP security model. Code Validation Builder provides an ability to perform pre-compilation analysis and generates warnings using 3rd party plugins created on top of MTJ. Also support for Java ME APIs javadocs in zip archives provided by the new version of MTJ. 

 Detailed information and download links can be found at the project page 

Friday Oct 24, 2014

Java ME Embedded is able to run with 256Kb of RAM only

Around a JavaOne conference timeframe we announced Java ME Embedded 8.1 Developer Preview release.  This release is bringing Java ME Embedded to a microcontrollers with ARM Cortex M architecture with mbed RTOS. Java ME Embedded is now capable to run on Freescale K64F board. The FRDM-K64F is an ultra-low-cost development platform for Kinetis K64.  The K64F board has a form-factor which compatible with the Arduino™ R3 pin layout, providing a wide range of expansion board options.

FRDM-K64F based on  MK64FN1M0VLL12 MCU (120 MHz, 1 MB flash memory, 256 KB RAM, low-power, crystal-less USB, and 100 Low profile Quad Flat Package (LQFP)) The FRDM-K64F is feature packed with a lot of peripherals to enable rapid prototyping. 

As always the best way to start with Java ME on any new platform is our Getting Started Guide, which can be found at Java ME Documentation page

What I would like to emphasize is a new Flasher capabilities of Java ME SDK. If you have a new K64 you can make it Java-enabled by just clicking "Flash" button in Device Connection Manager. I will explain you how to do it.

Firstly, if you have not installed mbed Serial Driver and USB Serial it is better do it using detailed instruction from K64 GSG

Then obviously you need a Java ME SDK 8.1 EA3 with new NetBeans plugins, which can be downloaded at OTN

Now you can check new flashing capabilities.
1. Go to t the Windows tray and click on Device Connection Manager 8.1
2. Click "Flash" button and pick your connected K64 board from the list following.
3. Say: "Wow, how cool it is to enable mbed device with Java capabilities!"

As I said before, K64 is a very convenient platform for prototyping. It has multicolor LED, switches and other peripherals on board. Let's make LEDs blinking.

Do not forget to set API permissions as described in one of my previous post If you have any question it is my pleasure to answer here or at Javas ME Embedded forum

Create a new MidLet and copy code below instead of generated. Do not forget to rename the class

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import jdk.dio.DeviceManager;
import jdk.dio.gpio.GPIOPin;
import jdk.dio.gpio.GPIOPinConfig;

 * @author abelokry
public class JavaMEOnK64 extends MIDlet {
    public void startApp() {
        try {
            String platform = System.getProperty("microedition.platform");  // Get Platform name it might be useful to identify the platform your midlet running and configure accordingly
        String productVersion = System.getProperty(""); // Get product version
        System.out.println("platform = " + platform + " version = " + productVersion);
            GPIOPin orangeLED = (GPIOPin); //Open Yellow LED see Getting Started Guide for details
            GPIOPin yellowLED = (GPIOPin); //Open Green LED, see Getting Started Guide for details
            for (int i = 0; i < 10; i++) {
        } catch (Exception ex) {

    protected void destroyApp(boolean unconditional) throws MIDletStateChangeException {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.

Wednesday Oct 01, 2014

Java ME Embedded Documentation survey

Java ME documentation team has put together a short survey (7 questions) which help us understand the best way to improve documentation for Java ME Embedded. Please invest 5 minutes of your time to return your investment in near future

Thursday Jul 31, 2014

LIBlets Signing Patch released

LIBlets Signing Patch available for download through Java ME SDK Update Center. This patch fixes JadTool that used incorrect JAD attribute for LIBlets signature. To apply this patch in NetBeans please follow the steps below.

1. Run Java ME SDK Update Center

2. Under "Available" tab you will see the new item (Internet connection required)

3. Click the check box and install the patch

4. Check if it is appeared under "Installed" tab 

Happy embedded coding with Java ME SDK! 

Friday Jul 04, 2014

Measuring temperature with Raspberry Pi, I2C sensor and Java ME 8

Nowadays, developers reveal their growing interest to the microcontrollers, devices based on ARM processors, and other non-traditional hardware. To satisfy the increasing demand, the market introduced  Arduino, Beagle Board, Raspberry Pi, and many other devices.
Oracle provides two Java platforms for ARM-based devices. Whereas Java SE Embedded is aimed for powerful hardware,  Java ME Embedded works better for resource-constrained devices.

Oracle Java ME Embedded is a Java Runtime optimized for constrained ARM based devices. Minimally acceptable requirements for Java ME embedded are 128Kb of RAM and 1Mb of ROM. Using Java ME Embedded in your projects can bring several benefits. First of all,  "write once, run everywhere" principle, now with some restrictions can be applied to embedded world. Second, AMS (Application Management System), integrated into the platform. enables deploying, updating, starting, stopping, and destroying applications. Third, you have an API to access peripheral, such as SPI, I2C, URAT, and GPIO pins (DAAPI - Device Access API). Forth,, you will get a free and powerful developer tools as well as a set of standard services: File I/O (JSR 75), Wireless Messaging (JSR 120), Web Services (JSR 172), Security and Trust Services Subset (SATSA – JSR 177), Location (JSR 179), and XML (JSR 280).

As you can see, Oracle Java ME Embedded is a cross-platform product, which supports a set of ARM based devices. The current version is Oracle Java ME 8. The platform is ported to ARM11/Linux (Raspberry Pi Model B), ARM9/BREW MP (Qualcomm IoE development), and X86/Windows (emulator). These are reference implementations developed by Oracle engineers. If there is customer’s need, the platform can be ported to other devices.

Smart home

Personally, I would really like to see my home automated. It is always a true pleasure to communicate with smart people and a real delight to live in a smart home. The first idea that usually strikes my mind when I’ve got a small piece of hardware is to automate something at my house. A typical task is a temperature monitoring.
To monitor temperature you can use UART, SPI, or I2C sensors. Usually, I2C ones are a bit cheaper, so that I will use Dallas Semiconductor DS1621 in DIP8 form factor to make a digital thermometer with Raspberry Pi and Java ME Embedded.

Raspberry Pi hardware setup

First of all, we need to physically connect the sensor and a RPi
pin1 - SDL
pin2 - SCL
pin4 - GND
pin8 - Vdd

If you read a datasheet of DS1621, you know that the sensor address at the I2C bus can be configured by pins 5-6-7. For our sensor, let's turn them all to 1 by closing contacts to the power.

Setup software at Raspberry Pi

Install Raspbian and update it.
To enable I2C interface on Raspberry Pi it is necessary to upload the relevant module
add 2 lines to /etc/modules


Reboot RPi
Install Linux tools to operate with I2C
sudo apt-get install i2c-tools

Detect an address of our sensor

sudo  i2cdetect -y 1

address is 4f (remember it)

Download Oracle Java ME Embedded 8  for Raspberry Pi Model B.
Accept a license agreements
Copy Runtime to Raspberry Pi to your favorite location and unpack it
for instance ~/JavaME/

Start Runtime with AMS (Application Management System) under the root privileges
sudo ~/JavaME/bin/
We have just  finished with the RPi setup

Developer tools setup

If you have not yet played with Oracle Java ME SDK 8, set it up for Netbeans.

Add our RPi as a deploying device
In NetBeans choose: Tools -> Java ME -> Device selector
The most probably your Raspberry already autodetected by Java ME SDK and exists in the list of connected devices. If it is not, you can find the Device Connection Manager in your Windows tray and add RPi manually.  To do it, just click add and write the IP address of your RPi and define a debug level you need.

Create a new project in Netbeans:  New Project -> Java ME -> Embedded application

IDE creates a skeleton of Java ME application, which extends a MIDlet class  and consists of 3 methods: startApp(), pauseApp(), anddestroyApp(boolean unconditional)

Java ME Embedded provides us with an API to communicate with peripherals – DIO API (Device Input/Output API). To operate with I2C, we need to create a configuration of the device, pass it to the factory, and if everything is alright, we will get an instance of the I2CDevice class required to communicate with the sensor.

To allow your application to use a specific API on the device you need to set up API Permissions.

In Netbeans click right button on your project in Project Properties go to tab Application Descriptor and to access I2C device add 2 lines:

Permission Protected Resource Name
Action Requested







To run a code below on your RPi, right-click  on your device in Device Selector window, and under "Run project" menu click on the project you would like to run on Raspberry. Alternatively,  you can use the project properties in Platform tab to define a Device. In that’s the case, NetBeans always uses RPi as a target device for deployment.

Now you should know the temperature in room.

The best collection of docs about Java ME Embedded 8 can be found here:
Have fun!

 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
 * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.

import javax.microedition.midlet.MIDlet;

import java.nio.ByteBuffer;
import jdk.dio.DeviceManager;
import jdk.dio.i2cbus.I2CDevice;
import jdk.dio.i2cbus.I2CDeviceConfig;

public class JavaMEThermometer extends MIDlet {

    private final int CFG_ADDRESS = 0x4f;  //Sensor address
    private final int FREQ = 100000;  //Bus frequency from Datasheet
    private final int ADDRESS_SIZE = 7; //Address size from Datasheet
    private final int BUS_ID = 1; // Internal bus ID in Java ME Embedded from Getting Started Guide

    // Registers addresses and definitions of configuration parameters of DS1621 from Datasheet
    private final int REG_READ_TEMP = 0xAA;
    private final int RT_ADDR_SIZE = 0x01;
    private final int READ_TEMP_SIZE = 0x02;
    private final int READ_TEMP_VAL = 0x00;
    private final int REG_ACC_CONF = 0xAC;
    private final int ACC_CONF_VAL = 0x00;
    private final int REG_START_CONV = 0xEE;
    private final int REG_STOP_CONV = 0x22;

    public void startApp() {
        // Create a configuration
        I2CDeviceConfig config = new I2CDeviceConfig(BUS_ID, CFG_ADDRESS, ADDRESS_SIZE, FREQ);
        I2CDevice device = null;
        try  {

            // Open device using configuration
            device = (I2CDevice);

            // Config sensor to continuous temperature measuring according to Datasheet
            write(device, new byte[]{(byte) REG_ACC_CONF, (byte) ACC_CONF_VAL});
            write(device, new byte[]{(byte) REG_START_CONV});

            // Read temperature
            ByteBuffer tempBuf = ByteBuffer.allocateDirect(READ_TEMP_SIZE);
  , RT_ADDR_SIZE,tempBuf);
             // Profit!  
            System.out.println("Temperature is:" + tempBuf.get(0));

        } catch (Exception ex) { // Bad practice. Only for consiceness
        } finally {
            // Close device
            if (device != null) {
                try {
                } catch (IOException ex) {
                // Destroy application


    public void pauseApp() {

    public void destroyApp(boolean unconditional) {

    private void write(I2CDevice i2c, byte[] buffer) {
        try {
        } catch (IOException ex) {
            System.out.println("[I2CThermometerTest] configure exception: " + ex.getMessage());
        } catch (Exception ex) {
            System.out.println("[I2CThermometerTest] Peripherial not available exception: " + ex.getMessage());

Tuesday Jun 17, 2014

Oracle Java ME Embedded 8.1 Early Access for Raspberry Pi

Less then two months ago the innovative Java ME 8 have been released. Now you are able to play with  Oracle Java ME Embedded 8.1 Early Access for Raspberry Pi. Download link:

You are also welcome to Java ME Embedded forum to discuss your thoughts on the new release


Topics including Java ME embedded, Java ME SDK, Internet of Things, Edge devices, Java on MCU and more


« May 2015