March 27, 2003
No More Java JokesRick Wayne
Channels, regular expressions and nonblocking I/O letJava catch up with other languages.
At his SD West 2003 tutorial, “Java’s New I/O,” Jason Hunter claimed that the new I/O library in Java 2 Standard Edition is really designed for server-side developers. “The good thing about back-end programming,” added the author of Java Servlet Programming and the JDOM XML library, “is that your boss never comes in to tweak it.” The new I/O—or “postmodern I/O,” as Hunter dubs it—may be hidden under the hood from end users, but it still has the potential to excite programmers. JDK 1.4 includes new capabilities and frees Java hackers from some ugly fetters. Among the new features cited by Hunter:
Hunter sprinkled bits of Java trivia throughout his talk, noting the way a
pretty woman spotted in a coffee shop got immortalized in every Java class file
(each one starts with the hex sequence
But along with the anecdotes, Hunter also delivered the goods on new features.
Leading off with file and network I/O, he explained how the new Channel classes
are more straightforward to work with. Since they use interfaces rather abstract
classes, it’s considerably easier to incorporate Channel functionality
in user or third-party code. They also provide new functionality. For one thing,
Hunter explained, channels can be bidirectional: the same object can both read
and write. He also expressed delight that Java finally provides file locking
for the programmer—no more hand-coded lock files! And the new memory-mapped
file objects are ideal for convenient access to data files, he said: Just hook
up the channel to a Buffer object, and programmers can treat huge datasets as
if they fit into memory. The Channel classes work hand-in-glove with the new
Buffer classes, which handle type-specific data ( “C and C++ programmers used to laugh at our blocking I/O,” Hunter told the class. He explained that in order to deal with multiple clients, Java programs previously had to fire up separate threads of execution. For something like a busy Web server, he maintained, the thread-per-client model hit the wall quickly. But now the new Selector mechanism lets a single thread register interest in many I/O events, and responds to them as they occur.
Hunter pointed out that Java programmers have felt the lack of regular-expression
support for a long time, and that the Apache project scratched that itch with
their “
|
|
||||||||||||||||||||||||||||
|
|
|
|