Jython

Jython is an implementation of Python in Java. Jython has the same syntax as Python 2.1, so many Python programs will also run in Jython. Jython integrates very closely with Java libraries - they can be imported and used almost the same way Python modules are used.

Jython turns Python into a scripting language for Java applications. You can write an entire application in Jython drawing on standard Java packages such as Swing and third-party libraries such as dom4j to implement some parts of the application. You can also use Jython as a scripting extension for an application written primarily in Java, and you can write web servlets in Jython.

If you work primarily with Java code, Jython is an excellent addition to your toolkit.

The main Jython web site is at http://www.jython.org. The online resources for learning Jython are a bit skimpy. The jython-users mailing list is helpful if you RTFM first and show the code that gives you trouble.

If you want to learn Jython, I recommend you learn the basics of Python first using any of these resources. Once you are comfortable with Python then you can try out Jython and focus on the way it integrates with Java.

Alternatively the book Jython Essentialsis a good introduction to Jython that doesn't assume you know Python. If you are going to do much with Jython you probably want this book.

Jython and Swing

Jython and Swing work great together. Writing a Swing GUI in Jython is much easier than writing it in Java.

Learning Python has a chapter on Jython that includes a substantial Swing example. Jython Essentials also has a chapter on Swing.

I have written a simple and complete example of using Jython and Swing to create a simple window with some buttons.

Finally, check out the demo programs that come with Jython.

Jython and dom4j

Jython and dom4j together comprise my favorite environment for working with XML data. dom4j makes it easy to work with the XML, Jython makes it easy to do everything else. I have written more about the combination here. In this essay I talk about one of the great features of dom4j - integrated XPath support.

Jython and Java Web Start

It's a bit tricky to use Jython with Java Web Start. Here is my recipe.