How J2ME programming model relates to J2SE, J2EE and Java in general? S V Ramu (2003-10-14) Prelude
It all started with the good fortune of getting a Nokia 6610 handset for GPRS connection, thanks to my employer. Though I primarily use it as a modem and not so much as a cell phone, the fact that it is java enabled, prompted me to try that out. This being the first time ever that I come anywhere near J2ME, the process was bit frustrating but very exciting. The verdict is, J2ME is cool and pretty easy! As usual, the goal is not be a tutorial, but to be a survey of the terrain. There are many good tutorial out there in web, of which I'll point to some. But more importantly, I'll focus on one key point that pestered me while starting in this area. That is "How is J2ME platform different from J2SE, which we are used to?". Once this is answered, I felt lot of the general Java skills can be immediately applied, knowing fully well, the limitations of J2ME. Nokia 6610 cellular phone
The first thing that I did, is what any new buyer of cell phone would do: explore the ring tones! My handset was quite capable, as the GPRS phones are normally bit costly, and are high end ones, than the regular cell phones. This phone comes with a PC connectivity software and a USB cable to connect the PC to the phone. The PC end of the cable connects to a USB port and the Nokia phone end has a PopPortTM , which is unique to Nokia, and is common to all its new phones and accessories. So with this, I could upload 4 track polyphonic midi song files to the phone. This is really cool. As said before, I use this phone primarily for its GPRS facility, which allows me to be always online (well, nearly always), with minimum fixed cost. GPRS (General Packet Radio Service) is a protocol, over the regular GSM (Global Mobile System) phones.
General Packet Radio Service (GPRS) enabled networks offer 'always-on', higher
capacity, Internet-based content and packet-based data services. This enables
services such as color Internet browsing, e-mail on the move, powerful visual
communications, multimedia messages and location-based services.
GSM World For the uninitiated, the GSM phones have the usual 10 digit phone numbers that are globally unique, in contrast to the CDMA (Code Division Multiple Access) devices, for WLL (Wireless Local Loop) applications. In India, CDMA phones for WLL use, like land line, has only max of 8 digits.
Sometimes called radio in the loop (RITL) or fixed-radio access (FRA), WLL is a
system that connects subscribers to the public switched telephone network (PSTN)
using radio signals as a substitute for copper for all or part of the connection
between the subscriber and the switch. This includes cordless access systems,
proprietary fixed radio access, and fixed cellular systems.
IEC Both GSM and CDMA are competing technologies for the cellular transmission. WLL is a local wireless connection to a network, and barring politics, can be used with both CDMA and GSM.
Since WLL is a wireless access method that uses radio waves to connect the
subscriber to a local central office, it can be implemented alongside a regular
PSTN (Public Switched Telephone Network), or be combined with digital wireless
technologies, such as CDMA (Code Division Multiple Access) and GSM.
ZDNet This is only the general overview. If you can write a novice friendly original article in this area, please do. We would be happy to publish it. Java landscape
The picture in the left summarizes it all. This is my adaptation of the the original picture that is available in the J2ME Data Sheet. Basically there are three reasons to draw afresh: one of course I didn't want to consider any copyright issues, secondly that is too rich and curvy for this site, and thirdly, and importantly, it depicts the J2EE as a separate stack. From what I see, every edition of the J2EE release depends fully on the latest (well, almost) available J2SE release. For example, the upcoming J2EE 1.4 beta 2 requires J2SE 1.4.1_02. So I understand, the idea of showing J2EE as a separate stack is only to reiterate maybe Sun's intention of growing J2EE as independent of J2SE. What would that mean? That means some part (package, class or restrictions) of J2SE may not be applicable to J2EE? I seriously doubt this, if history is any indicator J2EE will always be a superset of J2SE. Hence this diagram, where J2EE is stacked over J2SE. It is also compact, as a side effect.
I'm always intrigued by the thin line that separates a Language and its API.
This is not with Java alone, even in C and pascal, there are basic methods, or
libraries, which are integral to the language (like All this time I'm talking about basic Java. The usual way the java language is extended to a specific programming model is by
The basic trinity of Java platforms: J2SE, J2EE, and J2ME
As the number of API's of java grew, the confusion of which is mainly for server programming, which is for regular client programming, and which is for small devices programming, became glaring. There were plethora (more than few hundreds) of JSR (Java Specification Request), but not all are required for everybody. So the whole java programming is now separated into 3 broad editions.
As you can see in the figure, there are three ingredient to a java environment.
J2ME A highly optimized Java runtime environment, J2ME (Java 2 Platform, Micro Edition)
technology specifically addresses the vast consumer space, which covers the range
of extremely tiny commodities such as smart cards or a pager all the way up to
the set-top box, an appliance almost as powerful as a computer.
Coming to the core issue of J2ME, let us first try to map the ingredients of J2ME in comparison to Java in general. First you must remember, there are almost infinite varieties of small devices for which Java (J2ME) can be used. There are pagers, cell phones, PDA, Set Top boxes, even your own custom made robots, and many more. How can one software give the API for all these devices? You can't. For example, most cell phones have a way to vibrate when a call comes. There is a java API for doing this programmatically, but what use could this be to your say, coffee maker or set-top boxes? That is why, the whole J2ME arena is divided into many parts. Where, few parts can be used individually or together, and few others cannot be.
Although it would be nice to have the entire J2SE Application Programming
Interface (API) available on a micro device, it's not realistic. For example,
a mobile phone with its limited display cannot provide all the
functionality available in the Abstract Window Toolkit, the first graphical
user interface released with Java.
Core J2ME Technology and MIDP Virtual Machines: JVM, KVM, CVM
The J2ME is divided into the VM of its own (JVM, KVM, CVM), then the core API called the Configuration, the linguistic abilities of Java, which are very related to the VM implementation itself, and then the Profile, which depend upon the Configuration, and add more vertical (device dependent) capabilities to the platform. Beyond this you can have many Optional Packages (like an API for Bluetooth etc.), which can be added to suite your need. Of course there are dependencies between the profiles and the Configuration. For example the MID profile need CLD Configuration (more latter). And FP can only run with CDC, and not with CLDC. The Virtual machine, is the implementation backbone of the Configuration. It does many things that a Configuration needs, and the rest is handled by the classes. So much so, that people say that a VM is just an implementation of the Configuration for which it was written to support, and hence in the the modified J2ME stack image, we've clubbed configuration with the VM. The full blown JVM is what we know, as used in our J2SE 1.4.2 SDK, and which conforms to JLS 2.0. But Sun has two more VMs. One is the KVM, The Kilobyte Virtual Machine, which occupies barely 40-80kb of memory, 20-40kb of heap, and can run with 25mhz 16bit CPU. That is small. Then a CVM: Card VM, is smaller than that!
A configuration defines a Java platform for a 'horizontal' category or
grouping of devices with similar requirements on total memory budget and
other hardware capabilities. More specifically, a configuration:
KVM Whitepaper Currently J2ME has two configurations defined through JCP. CDC : Connected Device Configuration, CLDC : Connected Limited Device Configuration. CDC: Connected Device Configuration CDC supports the full Java 2 virtual machine specification, including floating
point support and core library features such as full class loading, thread support
and security. At the class library level, CDC uses J2SE class libraries whose
implementations have been optimized for small memory environments. In the interest
of resource conservation, some J2SE-based class libraries have modified interfaces,
while others have been removed entirely. The result is a flexible Java application
environment that fits comfortably within a memory budget of 2 MB of RAM and 2 MB
of ROM.
CDC-based technology is intended for use with a broad range of consumer and
embedded devices like smart communicators, pagers, personal digital assistants
(PDAs) and set-top boxes.
Sun CDC "CDC was designed around the two goals of J2SE compatibility and support for resource constrained devices. J2SE compatibility allows developers to leverage their investments in J2SE technology, including libraries, tools and skills". So for most practical purposes, the programming with CDC is similar to programming with J2SE. Except for restriction in using few of the rich APIs of J2SE. For a wonderful comparison of CDC vs. J2SE API, see the CDC API Comparison. The key thing to remember is that, java language wise, and JVM wise there is no difference between CDC and J2SE. Only the API support differ. Few of the major differences between CDC 1.0 and J2SE 1.3.1 are:
A profile is a set of standard APIs that support a narrower device category within
the CDC framework. A specific profile is combined with a configuration like CDC
to represent a complete Java application environment. CDC supports three profiles
for different product scenarios.
Sun CDC
Apart from these, XLet
is the application model derived from Java TV APIs.
The -let-s of Java World
You should have heard many At last! CLDC: Connected Limited Device Configuration CLDC is the foundation for the Java runtime environment targeted at small,
resource-constrained devices, such as mobile phones, pagers, and mainstream
personal digital assistants. CLDC, combined with the Mobile Information Device
Profile (MIDP), is the Java runtime environment for today's resource-constrained
mobile information devices (MIDs) such as phones and entry level PDAs.
Well, this is the area I used for Nokia 6610 programming that I was talking
at the start of this article. And this is the area, that prompted me to search all
these J2ME stuff, to help place it in perspective to a J2SE developer. Most of
the J2ME programming you'll see will relate to CLDC. As CDC devices are not
many, and is not user-programmable right now, IMHO. Somehow, creating a game
or application for our cell phone holds more potential use and charm to us, than
doing that for SetTop boxes. But in fact the line is thin! CLDC is highly constrained from a J2SE perspective, but is well endowed if you consider that we are dealing with memories like 128kb. Starting with CLDC and below (JavaCard), the whole of Java language as we see in J2SE cannot be implemented, and hence the JVM spec too cannot be adhered fully. So a constrained Kilobyte VM (KVM) is used exclusively for CLDC implementation.
As to the general relation between CLDC and J2SE, the Sun's KVM Whitepaper puts
it very illustratively. It goes on to add, 'Classes outside J2SE may not
use the
A Java VM supporting CLDC shall be compatible with Chapters 1 through 17 of The
Java Language Specification ...:
KVM Whitepaper
But considering the low memory environments, it is amazing that they still allow
Threads (of course they say, without preemptive multitasking, you have to
Just the three basic packages are included in the CLDC API set.
MIDP: Mobile Information Device Profile
That is pretty much all you have to program with CLDC alone. To be honest this is a decent set, and you can code interesting stuff with these. But you seldom need to do with CLDC alone. Most cell phones come with an extra package set called MIDP (there is now two MIDP versions), which adds extra classes which are either an alternative to the ones available in J2SE, or, are specific to most cell phones and PDAs (Mobile Information Devices, MIDs).
At the implementation level, a profile is defined simply as a collection of
Java APIs and class libraries that reside on top of a specified configuration and
that provide the additional domain-specific capabilities for devices in a specific
market segment.
In our example above, each of the three families of devices (cell phones, washing machines, and intercommunicating toys) would be addressed by a separate J2ME profile. Of course, the only one of these profiles in existence at the current time is the MIDP, designed for cell phones and related devices. KVM Whitepaper
The Mobile Information Device Profile (MIDP), combined with the Connected
Limited Device Configuration (CLDC), is the Java runtime environment for today's
mobile information devices (MIDs) such as phones and entry level PDAs.
What MIDP provides is the core application functionality required by mobile
applications - including the user interface, network connectivity, local
data storage, and application lifecycle management - packaged as a standardized
Java runtime environment and a set of Java APIs.
MIDP
It is important to note that there are lot of overlap in packages, classes
and methods in the CLDC 1.0, MIDP 1.0 and MIDP 2.0. For example the package
Apart from MIDP, there are many Optional Packages for CLDC, like (to name a few),
For more details into the exact differences between various, Configurations and Profiles read J2ME Technical Overview by Jesus David Rivas and Roger Riggs. This is elaborate and a good starting point for a comparative study. Of course above all you can download the J2ME Wireless Toolkit 2.0 itself, and explore the API doc and also run few demo programs that comes with it and runs inside a phone-like emulator. Very illustrative stuff. JavaCard
If, like me, you are thinking, programming to a pager or a cell phone is ridiculous enough, then programming to a chip embedded, visiting card size, smart card was a complete joke. If My 6610 can only take an application jar of size 64k max, and only three like that totally, what can we meaning fully do with a smart card, with memory as low as 16k or lower? This is what JavaCard tries to accomplish. An article on Java Card 2.0 specification says, 'the minimum system requirement is 16 kilobytes of read-only memory (ROM), 8 kilobytes of EEPROM, and 256 bytes of random access memory (RAM)'. We are talking that low! Well this is a very nascent area for me, and I think for the industry too, relatively. For a quick preview try this java world article. The APDU (application protocol data units) form the basic protocol of communication between the card and the reader, standardized by ISO 7816. Basically the idea is you write your java card application, and upload it into it, and a card reader application, together with that which is inside the card, by communicating with APDU, will do something useful. Following packages and classes are only used. As you'll see, it is a very very small subset of J2SE, and understandably so.
The following words should be familiar by now.
While Java Card technology enables programs written in the Java programming
language to run on smart cards, such small devices are far too under-powered to
support the full functionality of the Java platform. Therefore, the Java Card
platform supports only a carefully chosen, customized subset of the features
of the Java platform. This subset provides features that are well-suited
for writing programs for small devices and preserves the object-oriented
capabilities of the Java programming language.
JavaCard 2.2.1 spec But the idea that there will be something other than the regular class file format is interesting, though understandable.
The Java Virtual Machine Specification defines a Java virtual machine as an
engine that loads Java class files and executes them with a particular set of
semantics. The class file is a central piece of the Java architecture, and it
is the standard for the binary compatibility of the Java platform. The Virtual
Machine Specification for the Java Card Platform, Version 2.2.1 also defines a
file format that is the standard for binary compatibility for the Java Card
platform: the CAP (converted applet) file format is the form in which software
is loaded onto devices which implement a Java Card virtual machine.
JavaCard 2.2.1 spec For more information checkout the JavaCard 2.2.1 spec and implementation. Epilogue
Whew! we have come a long way. It all started with a simple HelloWorld program (just one class file, and one method overload), using Nokia Developer Suite for J2ME, 2.0. I thought of explaining that program to you all, but it is shamefully trivial. Instead I have done the survey route of the whole terrine of small device programming with Java using J2ME. Maybe in an another installment, I can explain a non-trivial program, at least moderately useful to me, in detail. I have few ideas. Let me try and and then brag about that to you. No! games are too far away from my mind now. I'm thinking of some useful numerical applications. OK, till then happy Java-J2ME time! |