04 April 2009

Jython Programming

  • Rapid application development - Python programs are typically 2-10X shorter than the equivalent Java program. This translates directly to increased programmer productivity. The seamless interaction between Python and Java allows developers to freely mix the two languages both during development and in shipping products.
  • Dynamic compilation to Java bytecodes - leads to highest possible performance without sacrificing interactivity.

  • Ability to extend existing Java classes in Jython - allows effective use of abstract classes.

  • Optional static compilation - allows creation of applets, servlets, beans, ...

  • Bean Properties - make use of Java packages much easier.

  • Making Jython Scripts Executable

    To make a jython ".py" file executable on a Unix system:

  • Make sure that jython is on your standard PATH.
  • Make the ".py" file executable. Typically, this is done with the command chmod +x foo.py
  • Add the following line to the top of the file:

#! /usr/bin/env jython


About performance
Because Jython is interpreted, it can be slower than a compiled language such as Java. In most applications, such as scripts or GUIs, this difference is hardly noticeable. In most cases, Jython's increased design and coding flexibility more than makes up for any small performance loss.

Because Jython code is dynamically converted to Java byte code, the latest enhancements to the Java platform (such as JITs and Sun's HotSpot JVM) can also eliminate many performance issues.

For an additional performance boost it is possible to implement code sections in the Java language and call them from Jython. For example, you could prototype your programs in Jython, test them out, and (in the case of performance issues) convert the critical sections to Java code. This technique is a good combination of the powers of Jython and the Java language, as prototyping is much easier in Jython than in Java.

No comments: