views:

270

answers:

3

I recently started learning Python and came accross the term Jython. From the Google search results, I thereby concluded that it is indeed a very important term. What is the experience programming/coding using Jython?

+11  A: 

Jython is just an implementation of the Python interpreter that runs on the JVM (Java Virtual Machine).

What is JPython?

JPython is an implementation of the Python programming language which is designed to run on the Java(tm) Platform. It consists of a compiler to compile Python source code down to Java bytecodes which can run directly on a JVM, a set of support libraries which are used by the compiled Java bytecodes, and extra support to make it trivial to use Java packages from within JPython. JPython has been renamed and superseded by Jython.

So coding in Jython is the basically same as coding in Python; with the advantage of having access to Java libraries.

Read: Jython FAQ, Why Jython?

NullUserException
+5  A: 

It's not just about the advantage of having access to the Java libraries. It's also being able to run on Java VM's with all their support and optimizations (i.e. JIT compilation).

Jython is also very usefull for scripting Java applications.

IronPython is a similar approach for the .NET CLI

Ivo van der Wijk
A: 

My recommendation to you: Forget about Jython and IronPython. Nobody uses them except the beginners and their developers. As for Jython, it's much slower, less robust, and less reliable than Python (aka CPython). It doesn't have the significant number of "batteries" that come Python; moreover, threading, process, and other lower-level inner-workings are different, resulting in subtle and hard-to-debug bugs.

OTZ
Well, i was just curious to know whether there are any real-world applications of Jython.
this.Liar
-1 "As for Jython, it's much slower, less robust, and less reliable than Python (aka CPython)" That's ridiculous and anecdotal at best. It's been years since Jython was slower than CPython. Jython is at least as fast as, if not faster than CPython.
NullUserException
@Insanity If you want a real garbage collector (rather than reference counting), which scales a lot better, and access to a wide array of resources with the Java libraries, use Jython.
NullUserException
-1, I regularly use a big java application that uses Jython to allow writing scripts for that application in Python. The embedding part is the big strength of Jython. And for "batteries", you don't get the Python libraries, but you get the Java ones.
Fabian
@Fabian "you don't get the Python libraries, but you get the Java ones". Yeah right -- libraries suited *for* Java with no particular advantages to Python. LOL
OTZ
@NullUserException "Jython is at least as fast as, if not faster than CPython." Now you are starting to sound like a devoted believer. Hello? Jython runs on JVM. What you think? Execution of bytecode on JVM is somehow faster than the native machine code on real CPU? Give me a break.
OTZ
CPython is far from native machine code, but both, CPython and Jython are python, and that is the important part. Speed is not one of the advantages of Python.
Fabian
@Fabian NO. Jython runs on JVM, a particular version of which in turn runs on a CPU while CPython, a compiled machine code on a particular CPU architecture, runs on a CPU without JVM. That's the big difference. Since CPython "interprets" python code or pyton bytecode, execution becomes slower than, say, C. But it is almost all the time faster than Jython. Understood?
OTZ
@otz CPython is also interpreted, but CPython has no JIT. I wouldn't bet that CPython is faster than Jython. And if you care about performance, Python is the wrong language. For typical use cases of Jython (e.g. embedding in a Java application), performance just does not matter. Which scripting language would you use inside a Java application? Jython is a perfect fit for that case.
Fabian
@Fabian READ MY COMMENTS. You haven't understood a thing. Also, as for that JIT thing, python dynamically compiles original Python code. Just because you use Jython doesn't necessarily make it superior to others. I'm sorry Jython doesn't have many users, support, documentation, a sophisticated set of libraries, and CPython speed, but that is the reality. You can keep using it if you want, but it comes nowhere close to Python's maturity and convenience.
OTZ
@otz With a hot JVM, Java is usually faster than C/C++. Java scales better too. Sure, you can write C/C++ code that's faster than Java code. But programmers who are able to do that are very, very few. And the resultant code is much messier too.
NullUserException
@otz Benchmarks have shown that Jython beats the crap out of CPython, especially when the datasets grow larger (thanks to Java's GC). Just look for them. (it has to be a recent one though, because Jython used to be a lot slower - not anymore)
NullUserException
See the benchmarks [here](http://www.smallshire.org.uk/sufficientlysmall/2009/05/22/ironpython-2-0-and-jython-2-5-performance-compared-to-python-2-5/). Mind you they are a year old, right now Jython is probably way better. The same thing happened with JRuby: it used to be slower than native Ruby, now it's faster. The JVM pwns C. Related: [How can JVM implementations like Jython and JRuby beat their native counterparts?](http://stackoverflow.com/questions/3488675/how-can-jvm-implementations-like-jython-and-jruby-beat-their-native-counterparts)
NullUserException
@NullUserException The benchmark only shows that CPython is faster than Jython in general. No? What's a "hot" JVM? I'm kinda disappointed that the benchmark doesn't even include PyPy and tests only a tiny fragment of computation types. It is vastly incomplete at best.
OTZ
@otz Yeah, CPython does alright until your dataset grows large - that's when the JVM's garbage collector kicks CPython's behind. Well, complain all you want, at least they bothered to perform benchmarks before spewing baseless assumptions like "Jython is much slower CPython". You are free to do your own benchmarks.
NullUserException
Java is a proven and enterprise-trusted piece of software. Hating on Java is just stupid. The "Java is much slower than C/C++" myth is one that just won't die in spite of overwhelming evidence of the contrary. Examples: [this](http://www.idiom.com/~zilla/Computer/javaCbenchmark.html), [this](http://kano.net/javabench/), and [the google search I used to find them](http://www.google.com/search?q=java+vs+C)
NullUserException
@OTZ Alex Martelli thinks [IronPython is fine](http://stackoverflow.com/questions/1905023/is-ironpython-usable-as-a-replacement-for-cpython/1905168#1905168). If even IronPython gets a stamp of approval, I'd bet Jython, which is a more mature project will too.
quantumSoup
Benchmarks are not good indicators of performance, but it is irrelevant which one is faster anyway, as the latest Java/Jython is fast enough in most use cases, especially if it is server based application. For us, we have used it successfully for the past 5 years, giving us use of libraries from both Python and Java world, often seamlessly.
Ron