CLDC API by R4R Team

CLDC API:

Introduction of CLDC API:

Here we have seen how CLDC fits into the bigger picture of J2ME and have set up our environment for development.
In this section, we delve a little deeper into the CLDC API. The CLDC API is really just a subset of the J2SE java.lang, java.io,
and java.util packages plus a new package -- javax.microedition. We will look at each of these packages in turn, highlighting the more important classes within each.
Although each of these classes exists in J2SE, the CLDC implementation of each class does not necessarily implement all methods supported by J2SE. You should check the CLDC API documentation to be sure which methods are supported.
A copy of the documentation is in the j2me_cldc/docs directory of your J2ME CLDC installation.

 Some important CLDC API are given below..

java.lang

The CLDC java.lang package is a subset of the J2SE java.lang package. Perhaps the most notable omissions compared to J2SE are floating point operations and, in particular,
floating point (Float) and double precision (Double) classes. These omissions have implications to all other classes if floating point is used.
When compared with J2SE v1.3 API, there are several other classes that are omitted from the CLDC API, including ClassLoader, Compiler, InheritableThreadLocal, Number,
Package, Process, RuntimePermission, SecurityManager, StrictMath,ThreadGroup, ThreadLocal, and Void.
We describe the main classes available in the CLDC java.lang package in the tables on the next few panels. The use of each of these classes should already be familiar to any Java developer.
In addition to these core classes, you will also see that the Runnable interface is supported by CLDC, as are the Exception, Error and related classes.

java.lang core run-time classes:

The  main core run-time classes for the java.lang package are:

 Class -- Represents classes and interfaces in a running Java application.
 Object -- As in J2SE, Object is the base class of all Java objects.
 Runtime -- Provides a way for a Java application to interact with the run-time environment in which it is running.
 System -- Provides several static helper methods, as with J2SE
 Thread -- Defines a thread of execution for a Java program.
 Throwable --
The superclass of all errors and exceptions in the Java language.

java.lang core data type classes:

The main core data type classes in the java.lang packages are:

 Boolean -- Wraps the boolean primitive data type.
 Byte -- Wraps the byte primitive data type.
 Character -- Wraps the char primitive data type.
 Integer -- Wraps the int primitive data type.
 Long -- Wraps the long primitive data type.
 Short -- Wraps the short primitive data type.

java.lang helper classes:

The main helper classes for the java.lang package are:

Math -- Contains methods for performing basic mathematical operations. Note that all the methods manipulating floating point values are omitted, leaving only the abs(),min(), and max() methods on integers and longs.
String -- Represents String objects in Java, as in J2SE.
StringBuffer -- Represents a string that can be modified, as in J2SE.

java.io input classes:

The CLDC API contains many of the commonly used input classes from J2SE. In particular,the CLDC java.io package includes the following  input classes:

ByteArrayInputStream -- Contains an internal buffer representing bytes that may be read from an input stream.
DataInput -- An interface that provides for reading bytes from a binary input stream and translating them into primitive Java data types. DataInputStream provides an implementation of this interface.
DataInputStream -- Allows an application to read primitive Java data types from the underlying input stream in a platform-independent way.
InputStream -- An abstract class that is the superclass of all classes representing an input stream of bytes.
InputStreamReader -- Reads bytes and translates them into characters according to a specified character encoding.
Reader -- An abstract class for reading character streams.

Note: that, as with the java.lang package, some of these classes may not contain all the methods supported by their J2SE cousin. In particular, the floating point and double precision methods are omitted.

java.io output classes:

The CLDC API contains many of the commonly used output classes from J2SE. In particular,the CLDC java.io package includes the following output classes:

ByteArrayOutputStream -- Implements an output stream where data is written into a bytes array.
DataOutput -- An interface that provides for writing primitive Java data types to a binary output stream. DataOutputStream provides an implementation of this interface.
DataOutputStream -- An output stream that allows an application to write primitive Java data types in a portable way.
OutputStream -- An abstract class that is the superclass of all classes representing an output stream of bytes.
OutputStreamReader -- Given characters, translates them into bytes according to a specified character encoding.
PrintStream -- Adds a convenient way to print a textual representation of data values.
Writer -- An abstract class for writing character streams.Some of these classes may not contain all the methods supported by J2SE, such as the
floating point and double precision methods.

java.util collections classes:

The CLDC java.util package contains the most frequently used classes from the J2SE java.util package. These include four of the collections classes -- actually three classes and one interface -- as well as date/time and utility classes.

The java.util collections classes supported by CLDC are:

Enumeration -- An interface that allows the calling routine to iterate through a collection of items, one at a time.
Hashtable -- Implements a hashtable, which maps keys to values.
Stack -- Represents a last-in-first-out (LIFO) collection or stack of objects.
Vector -- Represents a resizable "array," or vector, of objects.

java.util -- other classes:

The remaining java.util classes supported by CLDC include date and time classes and the Random utility class. These are given below:

Calendar -- An abstract class for getting and setting dates using a set of integer fields such as YEAR, MONTH, DAY, and so on.
Date -- Represents a specific date and time, with millisecond precision.
Random -- Utility class used to generate a stream of random int or long values.
TimeZone -- Represents a time zone offset, and also handles daylight savings adjustments.

javax.microedition.io:

So far, all the classes we have seen in the CLDC API have been a subset of the J2SE API.
CLDC also includes one additional package -- the javax.microedition.io package.
The only class defined in this package is the Connector class, a factory class that contains methods to create Connection objects, or input and output streams.
Connection objects are created when a class name is identified dynamically. A class name is identified based on the platform name, as well as the protocol of the requested connection.
The parameter string that describes the target adheres to the URL format required by the RFC 2396 specifications . Use the following format:
{scheme}:[{target}][{params}]
The {scheme} is the name of a protocol such as http or ftp. {target} is usually a network address, but non-network oriented protocols may treat this as a fairly flexible field. Any parameters, {params}, are specified as a series of assignments of the form ";x=y" (for example,;myParam=value)

javax.microedition.io helper interfaces:

In addition to the generic connection factory class, the javax.microedition.io package also contains the following connection-oriented interfaces:
Connection -- Defines the most basic type of connection. This interface is also the base class for all other connection interfaces in this package.
ContentConnection -- Defines a stream connection over which content is passed.
Datagram -- Defines a generic datagram interface.
DatagramConnection -- Defines a generic datagram connection and the capabilities it must support.
InputConnection -- Defines a generic input stream connection and the capabilities that it must support.
OutputConnection -- Defines a generic output stream connection and the capabilities that it must support.
StreamConnection -- Defines a generic stream connection and the capabilities that it must support.
StreamConnectionNotifier -- Defines the capabilities that a stream connection 

Leave a Comment:
Search
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!