|
Framework
Java
does far more than just wipe away memory management
issues. The Micro Edition of the Java 2 platform
(J2ME) has only the core functionality of the
Java 2 platform enterprise edition (J2EE). I needed
to develop a framework so that all my tools would
run on Mac, PC, and embedded platforms.
My
framework builds on the lowest common libraries
of the Micro Edition to simplify the networking
and to provide basic XML parsing and command dispatching
using best-practice design patterns. To jumpstart
a new project, all you need to do is hook into
this JAR supply properties file and specify UDP,
TCP, or multicast protocol and addresses.
Now
I can use XML to talk to an Internet application,
diagnostic tool, or the embedded devices (see
Photo 1). Multicast addressing enables the system
to be highly redundant and distributed. Using
UDP sockets also enables services to stop and
restart without having to reestablish connections
(as TCP would require). Packets are rarely (if
ever) lost on a LAN. I tried several stress tests
and never lost a single packet.
A
code snippet posted on the Circuit Cellar
FTP site shows you how a project hooks into the
framework JAR. You’re only required to instantiate
a sensor or device (e.g., an LCD screen or motor
controller) and register it with an API. This
keeps the project space tight. You must deal only
with your chosen XML syntax and the device’s public
methods. The API is a two-method interface the
developer must implement:
-
execute(Command command)
-
filterEvent(Object o).
This
framework is meant to be as simple as possible.
There are richer features in projects like Jgroups,
which is a toolkit for multicast communication
(www.jgroups.org). Code portability and reuse
should be the goal of all large software projects.
Java is by no means perfect, but it’s free and
used in many open-source projects.
|
-t.jpg)
(Click
here to enlarge)
|
Photo
1—The swing-based chat tool enables you to
see the XML commands and feedback. The TStik
(DS1820) has a 0.5° resolution. The AAG device
is much better suited to measure air temperature. |
Standards
and the communities of programmers continue to
make Java popular. Why pay for development tools?
Even though I cut my teeth on C/C++, Java showed
me what object-oriented programming was really
about. Oh, and don’t tell me, “Yeah, but Java
is slow.” That hasn’t been true for years. It’s
been the topic of many online discussions. Remember
that Java can be cross-compiled as well (http://gcc.gnu.org/java/).
|