Java Reference
In-Depth Information
Collections
Although the full J2SE Collections API is not supported by CLDC, the old familiar
Vector
and
Hashtable
classes remain, as well as the lesser-known
Stack
. If you are familiar with the J2SE
SDK
Vector
and
Hashtable
classes, you should have no trouble with them in MIDP.
Timers
MIDP includes the
Timer
and
TimerTask
classes that were introduced into J2SE in the 1.3 version
of the SDK. These are the only J2SE classes that are not included in the CLDC but are included
in MIDP.
Timer
's API is identical to the J2SE version with one exception. The constructor that speci-
fies whether the thread is a daemon is missing, as daemon threads are not supported in MIDP.
The
TimerTask
API is exactly the same in the J2SE SDK and MIDP.
Telling Time
J2SE has an impressive array of classes that can be used for specifying dates and times and
translating to and from human-readable representations of dates and times. The J2SE time
classes have four distinct responsibilities:
Points in time
are represented by instances of
java.util.Date
. If you think of time as a
line graph, then an instance of
Date
is just a point on the line.
•
•
Calendars
are used for representing points in time with calendar fields like year, month,
and day. If you're using a Gregorian calendar, for example, then you can translate from
a single point in time to a set of calendar values like month, day, and hours, minutes,
and seconds. In J2SE,
java.util.Calendar
is a parent class for calendars, while the
java.util.GregorianCalendar
class represents the Gregorian calendar system that is
familiar to most of the world.
•
Formatting
classes translate between points in time and human-readable strings. In
J2SE,
java.text.DateFormat
is the parent for classes that can both generate and parse
human-readable strings representing points in time. Formatting classes are very likely
to make use of a calendar. For example, a typical
DateFormat
implementation might use
a
GregorianCalendar
to translate a point in time to a set of calendar values, which it
would then format in a string.
•
Time zone
classes represent the time zones of the world. The
calendar
and
format
classes
use a time zone to create a localized representation of a particular point in time. In J2SE,
java.util.TimeZone
is the parent class of all time zones, with
java.util.SimpleTimeZone
as a concrete implementation.
Understanding these classes and their interactions is a little tricky, and it's complicated by
the fact that the APIs changed considerably between JDK 1.0 and JDK 1.1. The
java.util.Date
class used to have extra functionality in it; although the methods are deprecated, they're still
present and may be confusing. Fortunately, you don't have to deal with this in the CLDC/MIDP
world.
Search WWH ::
Custom Search