provided by: 
Originally published at Internet.comJava Programming Notes # 2574 * Preface * Viewing tip * Figures * Listings * Supplementary material * How the CLDC and the MIDP fit into the grand scheme of things * A simple example * The life cycle of a MIDlet * General background information * Preview * Discussion and sample code * The MIDlet named LifeCycle02 * The MIDlet named LifeCycle01 * Run the program * Summary * What's next? * Resources * Complete program listings * Copyright * About the author ---------------------------------
Preface
This is the third lesson in a series of tutorial lessons designed to teach you how to write programs using the Sun Java Wireless Toolkit for CLDC. The first lesson was titled Getting Started with MIDlets and the Sun Java Wireless Toolkit for CLDC (see Resources). The previous lesson was titled Capturing Output Produced by Programs Running in a Child Process.
A MIDlet development framework
In the first lesson I provided and explained a MIDlet development framework that makes experimenting with the programming of MIDlets fairly easy. In the previous lesson, I taught you how to capture and display the standard output and the error output produced by programs executing in a child process. I applied that knowledge to upgrade the MIDlet development framework from the earlier lesson.
What you will learn
In this lesson, I will tackle two topics. First, I will teach you how the CLDC and the MIDP fit into the grand scheme of things when programming MIDlets. Next, I will explain and demonstrate the life cycle of a MIDlet.
Viewing tip
I recommend that you open another copy of this document in a separate browser window and use the following links to easily find and view the figures and listings while you are reading about them.
Figures
* Figure 1. Output from program DateDemo02. * Figure 2. Output from program DateDemo01. * Figure 3. Output from the MIDlet named LifeCycle02. * Figure 4. Cell phone emulator output when MIDlet is in paused state. * Figure 5. Standard output from the MIDlet named LifeCycle01.
Listings
* Listing 1. Command for compiling a MIDlet. * Listing 2. DateDemo01.java. * Listing 3. DateDemo02.java. * Listing 4. Batch file to demonstrate class substitution. * Listing 5. Beginning of LifeCycle02 MIDlet program. * Listing 6. Beginning of the startApp method. * Listing 7. The pauseApp method. * Listing 8. The startApp method continues executing code. * Listing 9. The destroyApp method. * Listing 10. The startApp method executes even more code. * Listing 11. Beginning of the class named LifeCycle01. * Listing 12. The beginning of the startApp method. * Listing 13. When the running flag is true. * Listing 14. The pauseApp method. * Listing 15. The destroyApp method. * Listing 16. The resume method. * Listing 17. The beginning of the Toggler class. * Listing 18. Beginning of the run method in the Toggler object. * Listing 19. Wake up and do something. * Listing 20. Cause the MIDlet to enter the destroyed state. * Listing 21. The Thread class named Worker. * Listing 22. The beginning of the run method for the Worker class. * Listing 23. When the kill flag is false. * Listing 24. The Worker thread goes to sleep. * Listing 25. The MIDlet named LifeCycle02. * Listing 26. The MIDlet program named LifeCycle01.
Supplementary material
I recommend that you also study the other lessons in my extensive collection of online Java tutorials. You will find a consolidated index at www.DickBaldwin.com.
How the CLDC and the MIDP fit into the grand scheme of things
What are the CLDC and the MIDP anyway?
Let's begin by taking a look at what some others have to say on this topic (see Resources).
According to Wikipedia
"The Connected Limited Device Configuration (CLDC) is a specification of a framework for Java ME applications targeted at devices with very limited resources such as pagers and mobile phones."
"Mobile Information Device Profile (MIDP) is a specification published for the use of Java on embedded devices such as mobile phones and PDAs. MIDP is part of the Java Platform, Micro Edition (Java ME) framework and sits on top of Connected Limited Device Configuration, a set of lower level programming interfaces."
According to Vikram Goyal (see Resources)
"J2ME can be divided into three parts... a configuration, a profile, and optional packages. A configuration contains the JVM (not the traditional JVM, but the cut-down version) and some class libraries; a profile builds on top of these base class libraries by providing a useful set of APIs ... The configuration and profile are supplied by the device manufacturers and they embed them in the devices."
Continuing with Goyal:
"The most popular profile and configuration that Sun provides are the Mobile Information Device Profile (MIDP) and Connected Limited Device Configuration (CLDC), respectively. As the name suggests, CLDC is for devices with limited configurations; for example, devices that have only 128 to 512KB of memory available for Java
Author: Richard G. Baldwin
Read article at Internet.com site