Java Reference
In-Depth Information
The situation is somewhat simpler in CLDC/MIDP. There are fewer classes, for one thing,
and the
Date
class API has been cleaned up. In MIDP, the four responsibilities we just discussed
are assigned to classes as follows:
Points in time
are represented by instances of
java.util.Date
, just like before. The
Date
class, in essence, is just a wrapper for a
long
value that indicates the number of milliseconds
since midnight on January 1, 1970. (This is a standard way of representing time. It will
work for about another 290 million years, so don't worry about another millennium bug.)
•
•
Calendars
are still represented by instances of
java.util.Calendar
. However, the
GregorianCalendar
class is no longer part of the public API. To get a
Calendar
instance,
you can use the
getInstance()
factory method. Chances are you won't need to do this.
•
Formatting
classes are hidden from view in MIDP. One of the user interface classes,
javax.microedition.lcdui.DateField
, can convert a
Date
to a human-readable display,
eliminating the need for you to mess around with date formatters yourself. Essentially
DateField
is a graphic wrapper around a
Date
instance. It also allows the user to edit
calendar and clock fields to produce a new
Date
value. See Chapter 6 for a full discussion
of
DateField
.
Time zones
are still represented by instances of
java.util.TimeZone
.
TimeZone
offers
several static methods for examining the available time zones and getting an instance
representing a particular time zone.
•
Summary
Developers are bombarded with information, and the best developers are the ones who can
learn new material fast. Every once in a while, though, something you already know can be
used again. This is one of those cases—something you already know about, the J2SE APIs,
comes in very handy as you learn MIDP programming. MIDP's
java.lang
,
java.io
, and
java.util
packages contain classes that look and act a lot like the corresponding classes in J2SE.
Search WWH ::
Custom Search