J2ME Tutorials

1. Code sample to Send SMS from a J2ME application.

By: Leon : 2010-07-30

Description: A java application, where on making a Push to talk call, and the call does not get matured due the the callers phone being busy in another call, busy in packet data, switched off or not in coverage, the java appplication installed in the callers phone should send out a sms, automatically to the called number. The number to send the SMS is taken from the phone book for the called number.

2. Adding your own Application icon for your J2ME application (jar file)

By: Emiley J. : 2009-05-29

Description: Normally it is the default icon which is seen as soon as the installation of a jar file is complete.. if you want to see your own icon for launching the application after installing the jar file then here is how you can do this.

3. Play a multimedia file in J2ME Program (Audio/Video) using MMAPI

By: Vikram Goyal : 2008-08-18

Description: The simplest MMAPI MIDlet that can be built allows you to easily play a multimedia file from within your MIDlet without worrying about controls, feature sets, or security architecture. If all you’re doing is adding some sampled audio (or any other media) in a game, MMAPI allows you to do so in two lines of code. Listing below shows this code within a complete MIDlet.

4. Datagrams in J2ME (UDP Programming sample)

By: David Hemphill : 2008-08-01

Description: It is quite possible for someone to have worked with Java for some time without ever needing to understand or use datagrams. For mobile devices, however, datagrams offer some advantages in that they are rather lightweight when compared to TCP-based connections such as sockets. User Datagram Protocol, UDP, is one of the more common datagram protocols. However, because most datagram protocols follow the same basic principals as to their usage, the GCF is able to support datagrams generically.

5. Client Server in J2ME (Socket Programming sample)

By: David Hemphill : 2008-08-01

Description: Sockets are different than datagrams because they use a connection-based paradigm to transmit data. This means that both a sender and a receiver must be running and establish a communication channel for data to be exchanged. To use a real-world analogy, a socket connection is like calling a friend on the telephone. If the friend does not answer, a conversation cannot take place. Datagrams on the other hand are more like sending a letter to a friend, where a note is placed into an envelope, addressed, and mailed.

6. Using HttpConnection in J2ME (Retrieve web content from a website to a phone)

By: David Hemphill : 2008-08-01

Description: This J2ME example will cover reading data using the MIDP HttpConnection. Note that this connection interface is not part of the CLDC or CDC, but is defined rather in the MIDP and Personal Profiles themselves. The behavior of HttpConnection is one that combines an InputStream and an OutputStream into a single connection. A single HttpConnection may open and use exactly one OutputStream and exactly one InputStream. The order in which the streams are used is important as well. The OutputStream, if used, must be used before the InputStream. Once the streams have been used the connection should be closed and a new HttpConnection should be opened to continue communications if necessary. This follows the HTTP request-response paradigm.

7. Using HTTP vs UDP vs Socket in J2ME

By: David Hemphill : 2008-08-01

Description: In the case of MIDP, the specification only requires support for HTTP, although many devices support datagrams and sockets as well, because these protocols are needed to implement HTTP. However, before making commitments to datagrams or sockets it is a good idea to make sure they are supported on the platforms you are targeting.

8. RMSCookieConnector - Using Cookies in J2ME

By: Michael Juntao Yuan and Ju Long : 2008-08-01

Description: The RMSCookieConnector class stores cookies in an RMS record store. An RMS record store is accessed by its name, rather than reference, and can persist between soft resets, or reboots. That ensures an old session remains valid when a user later returns to an application after previously quitting it. Considering most people use their mobile information devices for many different tasks simultaneously, cookie persistence is a desired feature.

9. POST UTF-8 encoded data to the server in J2ME

By: Ash : 2008-07-29

Description: This sample code shows how to POST UTF-8 encoded data to the server in J2ME. The first requirement is to set the content-type for the connection. You should also use a OutputStreamWriter and pass "UTF-8" as the second parameter. Also note that the first parameter passed to this function 'data' should be encoded to UTF-8 bytes.

10. lists, forms, choices, gauges, text fields, text boxes in J2ME

By: Eric Giguere : 2008-07-10

Description: This example demonstrates how to create various GUI components. The MIDlet for this example allows you to test lists, forms, choices, gauges, text fields, text boxes, for example.