Jython: Python for the Java Platform [Pirates of the JVM]

Datetime:2017-04-18 05:30:21         Topic: JVM          Share        Original >>
Here to See The Original Article!!!

Make no mistake, the Dynamic Sea is anything but steady and calm. How did the wonderful island of Jython appear, you ask? It’s pretty easy actually: the Java tectonic plate met the Python tectonic plate and the rest is history. There are a lot of people who choose Jython as their destination because they love the way these two cultures melt together and create an exotic environment.

What do you like about Jython?

Click the image to see the whole Pirates of the JVM infographic.

Jython — Background information

JAXenter: What was your motivation for inventing Jython? What does Jython have to offer that other languages fail to provide?

Frank Wierzbicki:  For the majority of my career, I have worked on the Java platform and I am also a big fan of the Python language. Jython is an implementation of Python that runs on the JVM (Java Virtual Machine). I got started working on it as a way to bring more Python into my day job and stayed because of the great community.

JAXenter: Can you describe the core principles of the language?

Frank Wierzbicki:  Jython is a faithful implementation of Python, and Python was initially developed long before I became involved. A great summary of the design principles of Python (and the Jython implementation for that matter) is the “Zen of Python” which you can get from typing “import this” in the Python or Jython interpreter:

>>> import this
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!

What makes Jython an interesting implementation of Python

JAXenter: What would a typical program with Jython look like?

Frank Wierzbicki: Indentation is significant in Jython, and so the code blocks are always easy to see. The thing that makes Jython an interesting implementation of Python is that Java libraries can be imported and used as if they were written in Python. For example, the following is a code example where javax.swing components are called:

from javax.swing import JButton, JFrame

frame = JFrame('Hello, Jython!',
            defaultCloseOperation = JFrame.EXIT_ON_CLOSE,
            size = (300, 300)
        )

def change_text(event):
    print 'Clicked!'

button = JButton('Click Me!', actionPerformed=change_text)
frame.add(button)

The corresponding Java program is about three times as long.

JAXenter: For what kind of applications/use cases is Jython well-suited? For which ones it is not?

Java libraries can be imported and used as if they were written in Python.  

Frank Wierzbicki:  Jython is a good choice when you want to work with both libraries and frameworks from both the Java ecosystem and the Python ecosystem. For example, a programmer could use Django as a web development platform while still calling into Java libraries written by another team that prefers to develop in Java.

Jython would probably not be a good choice if a development shop wants to stick with a single programming language throughout.

JAXenter: What is the current state of the language?

Frank Wierzbicki:  Jython is on release 2.7.0, which implements the features in the Python 2.7.x series. We plan to release a 2.7.1 relatively soon, but I don’t have an exact date yet.

JAXenter: How about your plans?

Frank Wierzbicki:  We plan to continue releasing updates to the 2.7.x series of Jython. Long term we want to release a 3.x version, but that is a slow process as there were a large number of changes in the 3.x series.

Indentation is significant in Jython, and so the code blocks are always easy to see.  

JAXenter: How can people interested in Jython get started?

Frank Wierzbicki:  To get started as a user of Jython, you could have a look at our website  as well as the Jython book which can be read online . Find here  the hard copy.

Frank Wierzbickiis the head of the Jython project and Senior Software Engineer at Adconion Media Group. Frank’s most enduring hobby is picking up new programming languages, but he has yet to find one that is more fun to work with than Python.

Pirates of the JVM — The series:

Are you familiar with all the programming languages from the JVM universe? Have you discovered them all?

If the answer is “no”, we’ll leave no stone unturned in the search for knowledge. Therefore, the Pirates of the JVM infographic is accompanied by a series of articles in which we put the spotlight on the languages you may or may not know.

Don’t forget to check out thePirates of the JVMseries.








New