Introduction
This tutorial, the first in a three-part series, is designed for developers and product managers who are evaluating the Java programming language as an option for use in Global Positioning System (GPS) applications. More generally, anyone familiar with serial communications in another programming language such as C or BASIC, but who is interested in learning how to achieve serial communications by using the Java programming language, will find the sample application a useful exercise. Familiarity with the Java programming language is recommended. Tutorial resources contains links to useful primers on the Java language if you need to brush up your skills.
This tutorial is a prerequisite for subsequent tutorials in this series. Upcoming tutorials discuss GPS concepts in further depth as well as look at the task of porting the sample Java application from the desktop to a portable computing environment.
This tutorial explores GPS and the Java programming language's applicability to GPS applications. Basic GPS concepts serve as a foundation for the sample application. In addition to the GPS topics, this tutorial presents a high-level discussion of Java architecture with respect to the Java Native Interface (JNI) and platform-specific issues related to physical device communications. The tutorial works with the Java Communications API package for serial communications with a GPS unit. The sample application is also designed to be portable; therefore, the application employs the Java Abstract Windowing Toolkit (AWT) for the user interface.
- What is GPS? -- This section discusses the basics of GPS, including information on the official U.S. government agencies that have authority over the system and common applications and devices available for GPS. Subsequent sections examine the data protocols available for GPS (the tutorial's sample application optionally parses out National Marine Electronics Association, or NMEA, sentences), and the merits of Java for development of GPS applications. GPS applications are inherently portable and demand a versatile programming environment such as the Java environment.
-
Why Java for GPS?
-- This section shifts gears and delves into the development
environment of choice, the Java programming language. It explores JNI, which enables the
Java programming language to leverage native resources and talk to a
portable GPS unit, and the
javax.commpackage, which Sun Microsystems provides as a reference implementation of a JNI solution to device communications. The sample application employs this package. This discussion of the package examines the prescribed communications driver architecture. - Build environment -- This section walks through the acquisition, installation, and verification of the proper build environment required for the tutorial's sample application. The Tools section contains links for each of the tools used in the tutorial.
- Sample application -- The tutorial's sample application is constructed step-by-step in the this section.
- User interface and options for the sample application -- This section describes the user interface and the major options available to the user.
This tutorial's sample application demonstrates serial communications, Java graphical user interface programming, and GPS NMEA sentence parsing. The full source code is available for download from Tools. Here are the code snippets discussed in this tutorial:
- Verifying
the build environment -- The
verifybuildenvclass exercises core functionality of the Java Communications API, verifying the build environment. -
Ibmdwgps.properties-- This property file specifies required runtime parameters. -
Property access-- This code snippet demonstrates loading a properties file into the System object's properties collection. -
User interface-- This code creates the graphical user interface via the Java programming language's AWT. -
Action handler-- This routine processes events the user initiates. -
Start option-- The Start routine initiates communications with the serial port resource. -
Port configuration-- Serial ports have a variety of modes and parameters requiring configuration. This code demonstrates the steps necessary to prepare the port for use. -
Java I/O streams-- Java code "talks" to other systems by using a mechanism known as streams. This code sets up the streams necessary for interaction with the serial port. -
Serial event-- This routine handles data that arrives at the port's input stream. -
NMEA sentence parsing-- NMEA sentences represent various data from the GPS unit. This code employs a simple parsing technique to handle the NMEA message. -
Stop option-- TheStoproutine closes the communications resources. -
Save option-- TheSaveroutine prompts the user for a filename to save information into.
- GPS -- Global Positioning System, a networked system providing longitude, latitude, and elevation information to specially designed receivers.
- JDK -- Java Developers Kit, otherwise known as the Java SDK. This is the core Java toolset available from Sun Microsystems.
- Communications port -- Physical connector and circuitry in a computer used for the purpose of transferring information to another computer or device. Common examples include serial and parallel ports on personal computers.
- Portability -- The term given to software characterizing the ease with which you can convert an application from one platform to another; for example, converting a program that was written on the Windows platform and enabling it to run on a UNIX platform.
- Cross-platform development -- The practice of employing one operating system and/or hardware combination to develop applications for another platform. Developing a Palm OS application on a Linux computer is an example of cross-platform development.
- Data protocol -- The rules computers use when talking to one another. Common examples are found in Electronic Data Interchange (EDI), Hypertext Transfer Protocol (HTTP), File Transfer Protocol (FTP), X-Modem, etc.
The following resources are required to complete this tutorial:
- Java SDK (JDK) -- The Java SDK is the core Java development platform required for any Java application. You must install this to build the sample application. You can find the JDK at http://java.sun.com/j2se.
- Java
Communications API -- You can find the Java package,
javax.comm, used in the sample application for communicating with the GPS unit, at http://java.sun.com/products/javacomm/index.html. Follow the steps outlined below in the Build environment section to ensure proper installation of this package. - Tutorial sample code -- You can find the complete code to the tutorial's sample application at http://www.palm-communications.com/ibmdw.
- GPS unit -- The tutorial's sample application demonstrates communications with a consumer GPS unit available at http://www.garmin.com/mobile/. Any unit capable of producing NMEA sentences over a serial communications port is sufficient.

