Building Java ME Apps with Modern Tooling
Java ME, often known as J2ME, is a platform suitable for running Java applications on devices with limited resources, such as feature phones from before the iPhone era. Nowadays, feature phones like KaiOS utilize web technologies for their applications. Despite its decline, there may be an old phone lying around that you can use to create Java ME applications.
This guide demonstrates how to build a simple Java ME app using modern tooling and environments, without requiring any components from the outdated Java ME SDKs. It assumes a Linux-based terminal, but alternatives like Git Bash or similar Windows environments are also possible.
We'll start with a basic "Hello World" MIDlet, a component used in Java ME applications, which displays the text "Hello World!" using the LCDUI API. To compile the Java source, we'll need the stub JAR files from MicroEmulator, which include the CLDC 1.1 and MIDP 2.0 APIs. These files can be extracted to a 'lib' directory alongside the source code.
Midlets require metadata in a META-INF manifest file to function correctly. This includes essential information like the MIDlet's name, icon path, and the fully qualified class name of the entrypoint. Creating a 'resources' directory to store assets for the final JAR file is recommended. Additionally, a 16x16 PNG icon should be placed in the 'resources/icon.png' location.
Once everything is set up, we can package all the files into a JAR using the 'jar' command. Before running the app on a Java ME device, we need to preverify it using a tool like ProGuard. This process ensures the bytecode's validity for the KVM (Java Virtual Machine used in Java ME). For this example, we'll disable advanced features like shrinking, optimizing, and obfuscating the code to keep things simple.
After creating the 'app.jar' file, we can run it in an emulator or on a real device. The example uses a Sony Ericsson S312, a budget feature phone from 2009, which has a camera but lacks modern connectivity and storage options. In this case, Bluetooth is the easiest way to transfer files between the phone and a computer. Once the JAR file is transferred and installed on the phone, it will appear in the device's game list.
The example also demonstrates how to expand the app by drawing images on the screen. Using the same raccoon pixel art as the app icon, the code allows the images to bounce across the screen. The final build.sh script and example code can be found on GitHub for reference. Customizing the buildscript to match your OpenJDK 8 installation path may be necessary.
However, it's essential to understand the limitations of the Java ME platform. Applications are written in Java 1.3, which is significantly less feature-rich than modern Java versions. Additionally, the MIDP 2.0 API provides a much smaller standard library compared to Java SE. A comprehensive reference of available classes can be found in the old MIDP 2.0 API documentation.
Due to these limitations, developers often create multiple versions of their applications to cater to various phone manufacturers and their unique implementations of the Java ME platform.
Written by urgent.news from Lobsters's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.