Jython FAQ: Differences between Jython and Java

Saturday, February 14, 2009

In my previous posts, we have seen some important concepts in java and jython languages, in this FAQ section we will see the major differences between java and its scripting counterpart, namely jython. Even though seasoned java/python programmers can easily figure out the benefits of python implementation in JVM, but for those who are wondering what jython is and whats in it for java/python programmers or if you ask simply why should I care about jython, please follow this article.

For a customary introduction, the idea implementing of open source scripting languages in java started some years back and has given birth to many interesting languages like JRuby, Groovy, Tcl/Java, Jelly, BeanShell, Jython, Rhino, etc. In fact there is an interesting article on choosing a scripting language for java, in this section we will discuss things specific to jython.

1. What are the common applications of jython?

Jython is used mainly areas like unit testing, servlet programming, GUI programming and other lightweight applications on JVM, in general if you want a tool to simplify the way you want to work with java class libraries, then jython is for you.

2. What are the IDEs available for jython?

The best known IDE is the Netbeans port for dynamic languages, coyote, which includes jython as well, so if you are using netbeans for java, you can use coyote for jython application development.

If you are a C python programmer, IDLE will also help to make sure that you don't have any syntax errors and develop code with proper indentation rules for python/jython, then you can run the jython code in the command line using the jython interpreter (the method I prefer, I am a CPython programmer too), IDLE comes with CPython distribution.

With these basics, we can now see some differences between jython and java.

3. What about inheritance in jython from java?

Jython follows java rules, which means there is no support for multiple inheritance as you would do in CPython, so if feel you are smart like me to override java rules from jython, it will be in vain as I experimented before, do look at my article on extending java classes from jython to learn more. The important points are

3.1 Multiple inheritance is not allowed in jython, if you try to do so, you will get an error TypeError: no multiple inheritance for Java classes.

3.2 As obvious, when you have two java classes with the same name with one implemented in java and the equivalent one in jython, any jython code which imports the java class will import the equivalent jython class module.

4. How about implementing java interfaces in jython?

Implementing a java interface in jython is something similar to extending a java class which has no methods (the java interface), the jython class need not define all the java interface methods, but if it tries to invoke a method from the java class which is not overridden, an exception AttributeError: abstract method "javamethodname" not implemented, for more details do look at my detailed article on implementing java interfaces in jython.

In addition to these there are many subtle differences between java and jython like the way you can get the java class/interface objects and names in jython, the way jython handles java data types, etc, we will be looking at those in my future posts related to jython and java or continued from here.

No comments:


Copyright © 2008 Prasanna Seshadri, www.prasannatech.net, All Rights Reserved.
No part of the content or this site may be reproduced without prior written permission of the author.