|
YOUR FEEDBACK
Did you read today's front page stories & breaking news?
SYS-CON.TV |
TOP THREE LINKS YOU MUST CLICK ON General Java A Reality for Java Embedded Computing
A Reality for Java Embedded Computing
Oct. 1, 2001 12:00 AM
The Java development and runtime environment, with its "write once, run anywhere" paradigm, brings enormous advantages to the embedded industry. Java code is highly reliable, easily ported, and includes features such as Internet readiness, security, and the ability to download code at runtime to upgrade or extend applications. As such, it's ideal for Internet appliances (such as set-top boxes, Internet screen phones, or handheld devices) as well as traditional embedded devices (such as printers, medical devices, measurement and control instruments, telecommunication and data-communication equipment now connecting to the Internet). In Part 1 of this article (JDJ, Vol. 6, issue 9), we discussed some of the challenges of using Java for developing embedded systems and some of the solutions that are available to developers. In Part 2, we describe the benefits Java brings to the world of embedded software development. We also illustrate, based on a practical case study, how using Java for writing and running embedded software can benefit application developers.
Is Java Right for Your Embedded Device?
Java Benefits
To illustrate how using Java for writing and running embedded software can benefit application developers, we selected a single healthy-sized example of a Java application - suitable and also useful for embedded applications. The example includes the following characteristics: it uses a simple graphical user interface, it's network-oriented, it's based on an existing version of C for easy comparison, and it's simple enough for a quick port, but large enough to be a significant case study. Several aspects of this hands-on porting exercise are described below, basing comments on code snippets. The complete application source code is available for download on the JDJ Web site at www.sys-con.com/java/sourcec.cfm and can be freely used, modified, and distributed. The download package consists of application source code, documentation in javadoc format, Makefile, and precompiled class files and a .jar file. The application we chose is called jtalk, a port of the Unix talk command. Here's an excerpt from the manual pages on the talk command on a FreeBSD system (obtained by typing man talk on the FreeBSD 4.3 system): Talk is a visual communication program that copies lines from your terminal to that of another user. When first called, talk sends the message:The talk utility is a two-way, screen-oriented communication program. Once communication is established, the two parties can type simultaneously, with their output displayed in separate regions of the screen. The talk application sets up a peer-to-peer communication session with a remote user on another host. A talkd daemon has to be running on both the caller's and the callee's machines and act as a repository for active talk invitations from one party to another. The caller has to be able to leave an announcement on the callee's machine that an invitation exists and has to leave the invitation itself on the caller's own machine. Once the session is connected, the talk daemon isn't used; it's just peer-to-peer between the two talk programs. Since talkd daemons exist for Unix machines only, a port of talkd in Java was also created as part of this case study so talk can be used on Windows machines as well as in a non-Unix embedded Java application environment, such as Wind River's VxWorks and Personal JWorks. Note: There are two incompatible talk protocols of different ages. The older one uses UDP port 517 and is in use on Solaris. The newer one (which we chose to implement) uses UDP port 518 and is in use on BSD systems, such as FreeBSD or Wind River's BSD/OS. Technically, the port 517 protocol is called talk and the port 518 protocol is called ntalk. The port number 518 is currently hard-coded into jtalk and jtalkd. But it wouldn't help to change them to 517 because the older talk protocol on port 517 is incompatible. To run the jtalk program on your JVM, download the case study package, put jtalk.jar somewhere on your file system, add the location of jtalk.jar to your classpath, and invoke as follows: java com.windriver.jtalk.jtalk {person} [{terminal}]If the machine on which you're running jtalk doesn't run a talk daemon already, you'll have to first launch jtalkd with the following command: java com.windriver.jtalk.jtalkdThe syntax for {person} can be any of the following: username{terminal} is optional. It's required when responding to an invitation from someone with more than one login to be sure you get to the right one. If you can't run multiple JVMs on your system (which is the case on most embedded RTOSes), the download package includes a basic "shell" with a simple self-explanatory GUI to help you launch the jtalkd and jtalk applications: java com.windriver.jtalk.jtalkShellIf you want to recompile the source code, you can use the Makefile for GNU make included in the download package. The original C files from which jtalk was created are also included in the download package for your convenience. These files come from the FreeBSD 4.3 distribution. Choosing to port an existing Unix application, coded as a C program, was deliberate so a head-to-head comparison could be easily done between the C code and the Java code. Table 1 summarizes the major characteristics of the two versions. The experience with jtalk showed that Java can be used more productively as a language, and as a programming environment, than C/C++ for certain types of applications, especially in the embedded area. Some of the productivity advantages of Java are at the language level. For example:
package com.windriver.jtalk;
This loops every 30 seconds, remaking the invitation repeatedly until at some point accept() manages to complete before the SIGALRM is delivered. In the Java sources, we simply set a 30-second timeout on the ServerSocket. The equivalent accept() call then returns if there's no incoming connection before the 30 seconds elapse. We just have a simple loop in the Java sources (see Listing 6).
A Language and Platform Java's standard, complete, and easy-to-use APIs allow developers to write portable, more compact, more efficient, simpler, and more easily maintainable code than in C, for which network, threading, and graphics APIs are usually proprietary. In addition, developers can also benefit from the language's advanced concepts such as object orientation, packages, exceptions, and strong typing, as well as from the advantages offered by Java's development platform, including documentation generation, cross-platform portability, and security features (which enable them to write more efficiently for better code). Although it wasn't covered in this article, Java is ideal as an execution platform. Java's capability for dynamic and secure code updates provides the essential building block for creating an application and content-management framework that enables a service-delivery platform. Java's standardized API and portable code allows application developers to write platform-independent software content or services independently from embedded-system manufacturers. As long as applications are written to a Java specification that's compatible with the system's Java application environment, end users of such systems will be able to download, install, and run those applications on their systems. LATEST JAVA STORIES & POSTS
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
|
SYS-CON FEATURED WHITEPAPERS MOST READ THIS WEEK SPONSORED BY INFRAGISTICS
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||