Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.

Channels ▼

Book Review: Two Jython Titles

March 2003

Book Review: Two Jython Titles

by Cameron Laird

Jython for Java Programmers
by Robert Bill
New Riders, 2001
ISBN: 0735711119
460 pages, $49.99

Jython Essentials
by Samuele Pedroni, Noel Rappin
O'Reilly and Associates, March 2002
ISBN: 0-596-00247-5
304 pages, $24.95

Jython for Java Programmers (JJP) and Jython Essentials (JE) deliver what they advertise.

Two decades of Python

Python is a computing language. Although not as popular or widely-known as C or Java, its acceptance appears to have expanded a great deal over the past few years. Python is particularly easy and "safe" for newcomers; many learn it without a printed book.

On the other hand, Python also "scales" to accommodate large problems and teamwork remarkably well. That span — easy learning, power at the top end — contributes to its appeal. UnixReview.com frequently publishes book reviews and articles on Python.

Guido van Rossum invented both the Python language and its first interpreter or processor. He implemented the latter in C, and still does, 13 years later. In 1997, Jim Hugunin, then a doctoral candidate at MIT, had an excellent reputation in the Python community for his stewardship of Numeric Python. He also had enough courage to risk that reputation on what seemed at the time to be the wacky idea of re-implementing the Python interpreter in Java.

That's Jython: a Java-coded application that processes programs written in Python almost identically to the way the standard Python interpreter does. Instead of being wacky, Hugunin recalls the project as "consistently a pleasure", one that led to "a beautiful and elegant match".

What's the point, if the result is that programmers just write in the same language they were programming with before? There are a couple of fudges in the description of Jython above. The most crucial is this — along with everything standard Python knows, Jython manages Java-coded classes.

What it means

That means ... well, it means several things. If you're a Python programmer and you wish you could use a lovely new Java library you've heard about — you can! Use Jython rather than Python, run all your existing code through it, and sprinkle in a few:

  from java.lang import System

That's all it takes to access a whole new world of functionality.

There's more. Maybe you're responsible for development of Web pages, and you need to work up active client-side content. You're not as comfortable as you'd like with Java; you've always found it tedious or difficult for client-side Web work. No problem! Program in Python, and let Jython run your program in the Web browser.

Perhaps you're on the other side — good at Java, perhaps very good. You like Java. You like everything about Java, except that Swing is clumsy to use, and compilation can be slow, and sometimes it's a drag writing boilerplate. Also, regression testing takes longer than it should. And exposure of Java to your end-users as an extension language seems just to confuse and annoy them.

Jython to the rescue! Jython scripts Java — that is, it gives you an interactive, interpreted rapid application development environment for your Java work. With Jython, for example, you can write a complex Swing graphical user interface (GUI), bring it up live, and tune its widgets' placement, colors, and other attributes. Think of this as having the slickest debugger you've seen, one that gives you incredible ability to change data and even code on the fly, without loss of speed. Jython gives all that, and more.

Jython important for Java

Those situations partition the audiences for Jython for Java Programmers and Jython Essentials. Both books are well written, they both cover much of the same material, and they even inadvertently duplicate segments of the other's outline. If you're a Java programmer, get JJP. If you come from the Python side, or are new to both languages, you'll want JE.

The first part of that advice is particularly important. If you're a Java programmer, and reading this review idly, with no serious intention of following up, make a change right now. Get your own copy of JJP. You're probably familiar with modern interactive development environments (IDE) and the boost in productivity they give. My experience is that Java programmers who pick up Jython find it makes a bigger difference to them than their favorite IDE. Python programs are typically half the size, and take a third as long to write, as their Java correspondents. Those are enormous gains in productivity, and you can have them with Jython.

Even if you keep Java development walled off from Jython, Jython is superb for specific tasks such as unit testing of Java classes. Once you learn Jython, I think you're likely to conclude that you wouldn't want to work in Java without it.

And Jython for Java Programmers is nearly ideal for leading you into Jython. Author Robert W. Bill is thorough, accurate, and comprehensible. New Riders books have a healthy tradition of emphasizing working code. JJP is near the top in that regard; it's careful to explain everything in terms of specific executable source, all of which is correct, at least from what I've tested. The author has good taste. He's energetic enough to be explicit about all the questions a reader is likely to have (Does it matter which version? What's it look like when you do that? Why does X use the Java syntax, but Y the Python?), without being ponderous or excessive.

Jython for Java Programmers has a few faults. Editing is imperfect; there are incorrect word choices every chapter or so. The language itself is taught as version 2.0, which means readers miss out on several great Python features, including list comprehensions. There also are times when JJP makes me feel I'm too far into the Java world, where syntax is expected to be a problem. I suspect the chapters that explain Python as a language can be simplified. On the whole, though it's easy to recommend Jython for Java Programmers.

Jython Essentials is marginally less ambitious. Just over half the size of Jython for Java Programmers, it sacrifices depth more than topic. Both books touch on Beans, database connections, GUI development, servlets, advanced compilation, but JJP does so in more detail. There are also a few interesting subject, including PyUnit and XML programming, that Jython Essentials introduces but Jython for Java Programmers lacks. Also, JE is far more systematic about the differences between Jython and "normal" Python (often called CPython). An appendix lists all known for version 2.1.1.

Jython Essentials expects less background of the reader. An alert programmer with no experience with either Python or Java can safely work though JE, and will end up with much the same knowledge Jython for Java Programmers affords.

The prose of Jython Essentials is more to my general taste than Jython for Java Programmers is, but I think Jython Essentials also hurries a bit. I find I have to pay closer attention to JE. In any case, both books are well-written.

Even though these two books seem to split the market — one for Python backgrounds, one for Java — I don't think they exhaust the possibilities of Jython books. There's still a body of advanced Jythoneering, including high-productivity networking and test development, and Java-oriented use of new Python language elements, beyond their aim. It will be interesting to see where the Jython world is a year from now.

As Vice President of Phaseit, Inc., Cameron Laird programs in Python most days. He frequently reviews books for UnixReview.com, and co-authors the monthly Regular Expressions column.

Related Reading

More Insights

Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.