Python and Jython
Michael Chermside
mcherm at mcherm.com
Tue Jun 24 08:49:41 EDT 2003
Mulugeta Maru writes:
> My background is Java. I would like to know the difference between Python
> and Jython. Are they different languages? Should I learn Python first and
> then Jython? The reason I would like to learn the language is to use it with
> Java.
Jython and Python are the *same* language. This doesn't mean that they
are identical in all respects... there are several important differences.
But that's a lot like using Netscape's javascript versus Microsoft's...
(back before EMCAscript was standardized) if you stick to the basic things
they'll work the same way in both, but you can find lots of differences lurking
in the corners.
The most important differences are the truly fundamental ones that motivated
having two different implementations. CPython (the proper name for the C-based
version of Python, although people usually just call it "python") is written in
C. This means that it can be EXTENDED in C, and there are lots of useful
extensions (and some built into the standard distribution) that exist for
CPython which allow OS-specific features like Microsoft com objects and unix
interrupts, or to c libraries (several windowing libraries for instance), or
c's speed (Numeric and libraries for doing scientific computations). Jython has
none of these.
Meanwhile, Jython runs on the java virtual machine (although that isn't really
an advantage on portability, since CPython is more portable than the JVM). The
most important feature of Jython is that Jython progams can call Java objects,
Java programs can call Jython objects, and the Jython can be compiled into 100%
pure (compiled) Java code! The level of inter-language integration is really
astounding, and makes Jython the perfect choice for scripting Java programs,
interactively examining Java code, and so forth. Also, it means that Jython
programs can take advantage of Java's huge libraries. They have fewer OS-
specific features, but lots of useful things like JDBC, etc.
The other difference that I've noticed is that a lot more people work on
CPython than are working on Jython. As a result, CPython is a couple of
versions ahead of Jython and keeps adding new features. Hopefully Jython can
attract more volunteers and manage to keep up (because some of the new features
are pretty nice).
There are, of course, some syntactic differences... the page
http://www.jython.org/docs/differences.html will list some, but it is very
dated since CPython has changed a lot in since version 2.0 -- for instance, it
says that CPython lacks circular garbage collection, but that has since been
added. Nevertheless, it's a useful guide.
Since what you want to do is mostly to use Python with Java, I'd suggest that
you start out with Jython. You'll find that you can move to CPython anytime,
and that nearly everything you learned in Jython will work perfectly (except
that which depended on Java libraries).
-- Michael Chermside
More information about the Python-list
mailing list