This article mainly introduces the basic concepts of J2ME. Transfer from Chinese Java
Www.cn-java.com, I hope to help friends from beginner J2ME or intend to learn J2ME. I am also studying, you can communicate!
Noun
Here I lists some common keywords, which is convenient to refer to it. Detailed explanation.
J2ME (Java2 Platform, Micro Edition)
CLDC (Connected, LIMITED Device Configuration)
MIDP (Mobile Information Device Profile)
KVM (THE K Virtual Machine)
2. Background
As the wireless application and the embedded system is more interesting, Sun also launched J2ME to cater to this trend. (In fact, it is not a new launch. People who are familiar with Java history know that Java is originally In order to develop consumer electronics. Who knows, there is no heart to add Liu Ying, which is popular because of the excellent performance in the network application, so that the current J2EE, EJB, etc., the development is getting more and more huge. This time is killing A hroem gun. As for the performance, wait and see) SUN believes that future information devices will be more Customizable and Personal today. This can be seen from the popularity of mobile phones and PDAs. So in order to develop Applications facing these devices. Sun launched J2ME (Java2 Platform, Micro Edition).
3.J2ME basic structure
J2ME divides the equipment into two categories, one is a connection device, a finite connection device (Connected, Limited Device). The former one corresponds to devices that have power supply, abundant and larger power. For example: televisions, refrigerators, etc., the latter corresponds to mainly used batteries, small devices, such as mobile phones, PDAs, etc. Here I only involve the second, finite coupling device (Connected, Limited Device).
3.J2ME basic structure
Sun divides J2ME into two parts: Configuration and Profile.
Configuration includes virtual machine, the core class library and API. The Configuration layer defines the characteristics of a Java virtual machine and the minimum subset of the Java class library. In other words, the Configuration layer provides a developer's most basic and core Java platform. Just as mentioned above, J2ME divides the equipment into two categories, one is a connection device, one is a finite coupling device (Connected, Limited Device). There are two J2ME Configuration for these two devices. Is the CDC (Connected Device Con-normal, and CLDC (Connected, Limited Device Configuration), respectively. Here, please note that the CDC uses a classic JavaVM, while CLDC uses KVM (The K Virtual Machine).
Note: KVM is SUN to use a 16/32-bit RISC microprocessor or controller and it can be developed with a device that can be included in memory of 160kb ~ 512kb.
The Profile layer also includes a set of APIs, which is mainly for devices for a particular family. The Profile layer is implemented on a specific Configuration layer, and our programmer is responsible for writing an application on a specific profile. For mobile phones, PDAs, etc. Connected, Limited Device. Their PROFILE layer is called MiDP (Mobile InformationDevice Profile). The MIDP and CLDC constitute a complete J2ME architecture. By the way, there is also a unique name for the application Sun on MIDP, which is called MIDlet. Do you think it is a bit more familiar. Think about the applet in Java.
┌─────── ┐┄┄┄┄┄┄┄
│MIDLET │ Application
├────── ─ ┤┈┈┈┈┈┈┈
│ MIDP │ Proflie layer
├────── ─ ┤┄┄┄┄┄┄┄
│J2ME Core API │ Configuration Layer
├─────── ┤ CLDC
│ KVM │
├────── ─ ┤┈┄┄┄┄┄┄
│ Specific hardware │
└─────── ┘
Figure 1 J2ME CLDC & MIDP architecture
4. In-depth understanding of CLDC
The part of this section is translated from J2ME White Paper, which is boring, but keep in mind that after all, the correct concept is over everything.
CLDC's purpose
• For small, limited resources, and Connected Limited devices define a standard Java platform.
• Allow dynamics to publish content and applications to these devices.
· Convenient third-party software vendors and developers to transplant content and applications to these equipment.
Scope of CLDC
· Characteristics of Java language and virtual machines
· Core Java class library (such as java.lang. *, Java.util. *)
·input Output
· Support for network
· Support for security
· Support for internationalization
CLDC does not include the range (ie, is solved by MIDP)
· Management of application Life-cycle (that is, how the application is installed, run, delete)
· UI interface (user interface)
· EVENT treatment
· Advanced application mode (here referring to the user's interaction with the application).
CLDC security
The low-end virtual machine security is guaranteed by the verification step of the Class file when downloaded. (If you write and compile the MIDlet program, you will know that this step is necessary. There is a concept in this step. I will tell the specific steps in detail when you tell how to create a MIDlet program.
Application-based security By ensuring each application in a relatively independent enclosure environment and is not protected in the protected system package, it cannot be overridden.
Special aspects for Java language support
CLDC is always compatible with the Java language, but pay attention to the following points:
The floating-point data type (ie, there is no float and double) (this is actually mainly due to the device facing the CLDC, the hardware does not support floating point operations due to its memory restrictions or security considerations)
The endization of class instance is not supported, that is, the Object.Finalize () method is not saved. (Note: Finalization refers to another object cleaning method that is provided in Java. It can be found in Bruce Eckel, which is translated by Houjie, can be at www.jjhou Download in .com)
Limited error handling, that is, the subclasses of most java.lang.Error are not supported. In contrast, the CLDC includes a fairly complete exception class. Special aspects supporting Java Virtual Machine support
Substantially CLDC reached a compatibility of the Java virtual machine under its strict memory restriction. However, there is still the following differences.
· Does not support floating point data types (no float and double)
· Does JNI (THE JAVA Native Interface)
· Class loaders do not support user-defined Java-class loaders (Class Loaders)
· There is no reflection characteristic (Note: Reflection refers to Java through java.lang.Reflect, the ability to analyze the capabilities of the class. Commonly used to check the structure of the class, there is widely used on JavaBeans to see Gary Cornell's Core Java2 Volumei, II, machinery has a translation)
· Do not support thread groups or daemon threads
· Not supported by class instances (Finalization)
• No Weak Reference (Note: Weak Reference provides a way to solve objects that have been cleared by Garbage Collector. In Java2, please refer to java.lang.ref API document, and Sun website About Reference Objects and Garbage Collection articles.)
· Limited error handling (Error Handling)
4. In-depth understanding of CLDC (Part II)
The part of this section is translated from J2ME White Paper, which is boring, but keep in mind that after all, the correct concept is over everything.
Class Files Verification
CLDC requires the lower layer of virtual machines to identify and reject illegal Class files. However, because the CLDC itself is a small device for small memory consumption. Its class file detection mechanism is different from the standard file audit mechanism defined in J2SE. Please note the picture below:
Myapp.java
│
↓
┌── ┐
│JAVAC │┄ Compiler
└── ┘
↓
Myapp.class
↓
┌──── ┐
│preverifier │ ┈ Pre-audit
└──── ┘
↓
Myapp.class
│
↓ Download ...
┌─────── ─ ┒
│ ┠┄┄KVM operating environment
│ ┌─────── ┐ (Target Equipment)
││ Verifier │
│ └─────── ┘ ┘
│
│ ┌─────── ┐ ┐
││ │
││interpreter │G
││ │
│ └─────── ┘ ┘
┕┕━━━━━┛┛
Figure 2 CLDC / KVM audit process
Note the preverification process in CLDC. This is the key to CLDC distinguish between the usual class file audit process. As shown in the figure above, the source program must be prepared by the pre-trial verifier before being downloaded to the target device. The reason why this step is mainly to reduce the burden on the audit in KVM and accelerate the audit speed. Just as I mentioned above, this is for the hardware supported by CLDC (after all, the mobile phone and PDA did not pentium "core"! ^ - ^). I will remember this concept here. Specific operation methods I will introduce when writing MIDlet programs later. Class file format
Sun is required to package the Java application through JAR (Compressed Java Archive), which is no exception. So if you want to download your MIDlet program to the device, you have to pack it with JAR. Specific operation methods I will introduce when writing MIDlet programs later.
CLDC class library
If it is not strict, the CLDC's class library is a small subset of J2SE, which has the following approximate relationship, that is, J2SE includes CDC containing CLDC. But pay attention to CLDC is not fully included in J2SE, which also includes a class specifically for wireless facilities. So you can briefly divide the CLDC's class libraries to two parts: from J2SE inherited classes and CLDC proprietary classes.
(1) Class from J2SE inherited
This part consists of three packages, Java.lang, Java.util and Java.IO. Note that even if these classes inherited from J2SE, it is also greatly "shrinking water". For example, Java.util's class and interface is reduced by 47 of J2SE to 10. The other two have corresponding reductions.
System class
From java.lang:
Object, Class, Runtime, System, Thread, Runnable,
String, StringBuffer, Throwable
Data type class
From java.lang:
Boolean, Byte, Short, INTEGER, Long, CHARACTER
Container Class
From java.util:
Vector, Stack, Hashtable, ENUMERATION
I / O class
From java.io:
InputStream, OutputStream, ByterrayinputStream,
ByteArrayoutputstream, DataInput, Dataoutput,
DataInputStream, DataOutputstream, Reader, Writer,
InputStreamReader, OutputStreamWriter, PrintStream
Date and time class
From java.util:
Calendar, Date, Timezone
Additional practical class
Java.util.random, java.lang.math
Exception classes
From java.lang:
Exception, ClassNotFoundException,
ILLEGALACCESSEXCEPTION, InstantiationException,
InterruptedException, RuntimeException,
ArithmeticException, ArrayStoreException,
ClasscastException, IllegaLargumentexception,
IllegalthreadStateException, NumberFormATexception,
IllegalMonitorstateException, IndexOutofboundsexception,
ArrayIndexOfboundsexception, StringIndexOutofboundsexception,
NegativeArraysizeException, NullPointersRexception,
SECURITYEXCEPTION
From java.util:
EMPTYSTACKEXCEPTION, NOSUCHELEMENTEXCEPTION
From java.io:
EOFEXCEPTION, IOEXCEPTION, InterruptedException,
UnsupportedEncodingexception, UTFDataFormatexception
Wrong class
From java.lang:
Error, VirtualMachineError, OutofMemoryError
(2) CLDC proprietary class
Here SUN provides javax.microedition.IO package. Use it to provide bridges communicating with the outside world. (Note: Just as in J2SE we use java.net. *) Note that all connections are created by javax.microedition.connector. For example: You can open an HTTP connection through connector.open ("http://www.chinajavaworld.com")
Javax.microedition.IO interface includes:
Connection, InputConnection, OutputConnection,
StreamConnection, ContentConnection, DataGramConnection,
StreamConnectionNotifier
Here, you can also see that you can also see that the class library included in CLDC is not enough to develop applications. For example, there is no support for the UI interface, etc. This is also the design concept of CLDC. CLDC itself never wants to solve all problems. These issues are resolved by PROFILE-MIDP on the upper layer. For example, javax.microedition.lcdui is the UI package defined in the MIDP.