Getting Started with Jython
Introduction to Jython - a Python implementation on the Java Virtual Machine - covering basics, database connectivity, and Java integration.
As you can guess from the name Jython is an amalgamation of the Python and Java programming languages. It is one of three implementations of the Python language, the other two being CPython and IronPython (.Net). Jython is one of the most mature JVM languages that is available on the Java platform.
The language provides many benefits from both of the languages including java byte code utilization, reusability of java classes and interfaces, Python’s simplified syntax, and many more. Since it is a JVM language it can maintain Java’s “Compile once, run anywhere” slogan and also has access to thousands of Java’s API libraries.
In order to use the language you need to go download Jython from jython.org.
Hello World in Jython:
print "Hello World!"
Database connectivity options:
- zxJDBC - Jython’s DBI implementation, good for simple one-off scripts
- JDBC - Using Java’s JDBC directly
Using Jython modules (classes) in Java programs involves creating object factories which convert Python objects into Java objects. There are two main ways of doing the factory process - one involves making a factory for each object, and the other involves a more loosely coupled factory that can generically handle all of the objects.
For more about Jython basics see the “Definitive Guide to Jython” found here.