RS-232 serial ports are one of the oldest I/O technologies still in use today. They really haven changed a lot in the last 20 years. RS-232 serial ports work reliably and work well, but a 20-year-old technology designed for 300-baud modems, daisy-wheel printers, and 16-bit processors with 4.77-MHz clock rates doesn suffice for digital video, DVD burners, and optical mice. Consequently, more modern computers have switched to a different serial protocol known as Universal Serial Bus (USB).

Hardware-wise, USB is much faster and thus better suited for the data transfer needs of todays more bandwidth-hungry devices. USB also uses a different connector thats much easier to plug in and unplug and less susceptible to bent pins and broken ports. USB cables carry power as well as data, so small USB devices that don draw a lot of current don need separate power cords. However, to a Java programmer there are two key differences:

  1. Many different devices can be connected to the same USB port. Indeed, up to 127 different devices may be daisy chained to a single USB controller.

  2. Data is sent to and received from USB devices in individual I/O request packets (IRPs). The stream classes are not used.

This makes communicating with USB devices more complex than reading and writing the streams from the single device on a serial port.

There are several extant versions of USB. The basic architecture and APIs are the same regardless of version. As a software developer or end user, the primary difference is speed. USB 1.0 and 1.1 support low-speed 1.5-Mbps connections and full-speed 12 Mbps connections.[*]USB 2.0 adds support for high-speed 480-Mbps connections. High-speed devices can normally fall back to full speed when attached to a USB 1.1 hub or controller. Furthermore, not all USB 2.0 devices are high speed. My typing speed is 30 words per minute at best. A low-speed USB keyboard is more than adequate.

[*] Thats megabits per second, Mbts, not megabytes per second, MBps.

USB communication is not a standard part of the JDK. It is available as a standard extension in the javax.usb package. IBM has published an open source implementation of this API for Linux that can be downloaded from While, like most things Java, this API is at least theoretically platform independent, currently this is the only available implementation. It has not yet been ported to the Mac, Windows, or other platforms.

The Java USB API is a very low-level API that closely mirrors the actual USB hardware and protocols. It involves a lot of bit-twiddling and byte manipulation. A number of higher-level protocols, such as the Human Interface Device (HID) class and the Mass Storage Driver, sit on top of the raw USB API. The Java USB API does not support these higher-level protocols. They can be implemented on top of the low-level USB API Java does support, but this is a decidedly nontrivial undertaking.

Its worth noting that many USB devices are already available to Java through native system drivers. Java treats a mouse connected via USB the same as it does one plugged in through the serial port or wirelessly with Bluetooth. A digital camera looks like any other mounted filesystem. The Java Printing API works the same whether the printer is connected via Ethernet, parallel cable, or USB. However, if you want to talk to a device thats a little different, that isn just another kind of mouse or filesystem or printer, youll need to use the Java USB API. For instance, Java does not have an API for controlling scanners. However, if the scanner is connected via USB, the USB API enables you to send the scanner commands and receive data from it. (This is much more important for custom laboratory equipment than it is for typical off-the-shelf consumer products.)

Basic I/O

Introducing I/O

Output Streams

Input Streams

Data Sources

File Streams

Network Streams

Filter Streams

Filter Streams

Print Streams

Data Streams

Streams in Memory

Compressing Streams

JAR Archives

Cryptographic Streams

Object Serialization

New I/O



Nonblocking I/O

The File System

Working with Files

File Dialogs and Choosers


Character Sets and Unicode

Readers and Writers

Formatted I/O with java.text


The Java Communications API


The J2ME Generic Connection Framework


Character Sets

Java I/O
Java I/O
ISBN: 0596527500
EAN: 2147483647
Year: 2004
Pages: 244 © 2008-2020.
If you may any questions please contact us: