Java biking
Launching a full-blown IDE for a brief Java
programming excursion can be like driving the car to a nearby shopping mall. If
you have ever imagined the equivalent of a Java bicycle, your fantasy may have
come true with BeanShell v. 1.0.
I'd just moved to Davis, California, and it was the first time I'd gone
shopping. I parked my bicycle in an empty rack, dashed in, grabbed the few
things I needed, and found a checkout register.
"Pehperohplahstig."
"Sorry?" The salute was unexpected, and the tinny accent of the
northern-California girl didn't help.
"Paper-or-plastic?" she repeated, more slowly this time. But it
wasn't until the third time that I understood.
"Oh! Paper bags will be OK. Thanks."
The reply "You bet!" was another surprise, but I didn't ask for translation.
I paid, gathered my stuff,
and hurried out, glad I could cycle home quickly with my groceries.
As a young programmer, I was always in a hurry, and if there's a
heaven for bikers, it is the little town of Davis. My apartment was well within walking distance
of the
shopping mall, but I preferred to ride.
It took only a few minutes to reach the mall
by bike, most of them spent waiting at the
Russell Avenue crossing. Driving would have been overkill for such a short trip --
especially considering the effects on the ozone layer -- and probably the
most time-consuming of the options.
I've often felt that launching a full-blown development
environment for a brief
Java programming excursion is like taking the car out to go to
the nearby mall. Yet going about with just a text editor and the
command line compiler seems too cumbersome, too much like going on foot -- especially if the task at hand
is not trivial, or if it's one of those days when one out of ten key-presses is a typing
error. The solution I've imagined would be something equivalent to a Java
programming bicycle.
I went Web-spelunking and found a beta version of what promised to be the ideal solution to my short programming
excursion needs -- someday. Then, just a couple of weeks ago, I was notified by e-mail that BeanShell 1.0
was available. I decided to
take the tool for a ride.
BeanShell 1.0
BeanShell is a small
interpreter written in Java by Pat
Niemeyer. It executes standard Java statements and
expressions in addition to several scripting commands. The tool
supports scripted objects as simple method closures like those in Perl and JavaScript. BeanShell
is open source and free to use under the terms of the GNU General Public
License.
BeanShell comes with both GUI (Swing) and console mode
interpreters. The GUI interpreter provides command history recall,
command line editing, cut and paste, support for multiple sessions,
and a simple editor for scripts.
The language interpreted by BeanShell is very similar to
JavaScript. There's no need to declare variables or parameter
types; the tool does type checking at runtime. Any class, object,
or method available to the Java interpreter can be accessed from
within BeanShell using standard Java syntax. The interpreter
understands Java import statements, and it provides a convenient
syntax for accessing Java Bean properties. External commands can be
invoked from within the interpreter using the exec command, so you can also access other tools, like your favorite
editor or the Java compiler, from within the shell. Several other
useful commands and variables -- such as dir, print, and cwd --
are provided by default, and the built-in command set can be
readily extended using either BeanShell scripts or Java.
BeanShell can also be embedded into your applications to provide
them with scripting functionality. The core interpreter, with all
console functionality removed, fits in a 135K Jar file. The tool
also provides a "server mode," which allows for remote access to the
interpreter using HTTP. Upon gaining access to the specified TCP port,
BeanShell will send back a remote console applet that can be used
to query or change the state of the running application in which
BeanShell is embedded. It's also possible to talk to the
interpreter in terminal mode by using the Telnet protocol.
The documentation, which is available from the BeanShell Web site, includes the script language's syntax, the built-in commands, and
instructions for installing, running, and embedding the tool. A
set of JavaDoc pages covers the product's internal API. There is a mailing
list for BeanShell users and developers on the site as well.
With BeanShell at hand I can easily experiment with libraries
and classes I develop or download from the Internet without recompiling,
and without bothering to set up a new project in the IDE. As it turns out, my
Java bike was not just a fantasy after all.
|
Connect with Us