Coffee-drinking snakes: Java and Python
Introduction
Java and Python are very different languages – yet, it is amazing to note the constant comparisons made between the two languages contrasted with the synergy between the two languages in the form of Jython.
Comparing Python and Java
Every Python programmer knows that he/she can achieve a lot more in a lot less code using Python than most other languages, but how much better is it really? Well, in an article titled Python & Java: a Side-by-Side Comparison, the author claims that you can be 5-10 times more productive in Python than in Java. My personal experience with these languages tells me this is quite true. This article further compares the static typing of Java vs the dynamic typing of Python, the verbosity of Java vs the compactness of Python along with head-to-head equivalent code comparisons. A very interesting read, indeed.
Combining Python and Java
Jim Hugunin (creator of Jython) says
"The purpose of a programming language is to let software developers express their intentions as simply and as directly as possible."
Nobody would dispute this statement. It marks the necessity of a good programming language and good tools to enable a better software developer. Taking this into account, a combination of the excellent Python language with the comprehensive libraries of the Java platform would be an extremely compelling combination. This is where Jython comes into the picture.
Jython is an implementation of the Python language written in the Java language! This means that you can run your Python programs using Jython – the interesting part is that Jython itself is written in Java. This allows you to use the Java libraries from your Python programs. For example, here is a Swing "Hello World" program written in Python and run using Jython:
from javax.swing import JFrame f = JFrame('Hello World') f.setSize(200, 100) f.show()
Jython is slowly becoming an important part of every Java developer’s toolkit. It allows rapid scripting as well as testing of your Java programs using an interactive prompt. It is interesting to note that you can compile your Jython programs into Java bytecodes. So, you could write Python code behind your boss’s back and claim that you wrote that Java program he asked for already!
Here are some interesting articles to further explore Jython: