Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I am very interested in Python for programming on the JVM, and I've worked in Java and Ruby (not JRuby) a lot, and to a certain extent in Groovy.

What are the limits to the Java-Jython and Java-JRuby integration right now? What about Groovy: are there any things that a Java class can do that a Groovy class cannot? And what about IDE integration (mostly Eclipse, but IntelliJ and Netbeans are also interesting)?

I'm not interested in whether Python, Ruby or Groovy is better/more-concise/whatever. I'm just interested in how well they are working in the JVM and tools (especially IDEs) right now. My main interest is not inside a web server, if that matters.

Simple examples of getting a HelloWorld which extends a custom Java class and implements a custom Java interface would be very useful to me.

share|improve this question
add comment

closed as too broad by MichaelT, gnat, Bart van Ingen Schenau, Michael Kohne, GlenH7 Mar 8 at 21:23

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.If this question can be reworded to fit the rules in the help center, please edit the question.

3 Answers

up vote 4 down vote accepted

I have no experience of JRuby nor Groovy. But Jython:

  • Excellent integration with NetBeans. NetBeans can run Python programs with Jython almost straight out of the box, just install the "Jython Distribution" plugin and you're done. Apparently Eclipse works as well. See chapter Using Jython in an IDE in the Jython Book.

  • Java-Jython integration is excellent. Calling Java from Jython is super easy. Calling Jython from Java is not quite as straightforward (Java was not designed with Jython in mind), but still fairly easy. I've mostly had luck with creating a class in Jython (extending a Java class/interface), and then creating instances of that class in Java using an object factory. See Jython and Java Integration for how-to.

Extending a Java class in Jython works like this:

from javax.swing import JFrame, JButton

class MyFrame(JFrame):

    def __init__(self):
        self.defaultCloseOperation = JFrame.EXIT_ON_CLOSE
        self.size = (300, 300)
        self.add(JButton('Click Me!', actionPerformed=self.print_something))
        self.visible = True

    def print_something(self, event):
        print 'Clicked!'

Implementing interfaces works similarly, just import the interface, "extend" it using a class definition such as class MyClass(MyInterface) and implement what's needed.

My only criticism against Jython is that its raw performance is not very good (and that's mostly because it uses massive reflection to interact with Java). But then, raw performance is usually pretty irrelevant for a scripting language.

share|improve this answer
Great stuff +1. Any idea how Jython performance compares to Groovy's (also massively reflection-based) performance? –  Yar Oct 22 '10 at 7:01
I haven't personally compared them, but Google seems to find lots of opinions: www.google.com/#q=jython+vs+groovy+performance –  Joonas Pulakka Oct 22 '10 at 7:32
Google? Who's that? Looks like jython is worse than any of the other non-Java JVM langs. Interesting. –  Yar Oct 22 '10 at 15:05
People use Python for full-fledged desktop apps, so performance matters somewhat. Are you sure that Jython uses the Java reflection APIs. (Are you sure it hasn't adopted the techniques that Groovy and JRuby have? See blog.headius.com/2008/05/power-of-jvm.html and many other posts on the same blog for more discussion of performance.) –  Ken Bloom Dec 16 '10 at 14:32
@Ken Bloom: Yes, I wouldn't use Jython for full-fledged desktop apps, because it's quite slow (but I am using it embedded inside full-fledged Java apps). I'm quite sure that Jython uses mostly reflection APIs - unlike Groovy or JRuby, Jython's code base actually originates from the last millennium - although they may have made some optimizations lately. Thanks for the interesting blog link! –  Joonas Pulakka Dec 16 '10 at 14:49
show 1 more comment

For the last year, I've been working a lot with Groovy (and Java as well, but more Groovy).

IDE integration: OK in Netbeans. Since Groovy is dynamic, don't expect the same level of IDE support like Java (Intelisense, Refactoring etc.). Some people say that InteliJ is even better, but my coworker who checked it out didn't like it. YMMV. Last time I checked, support in Eclipse was not as good as in Netbeans.

Groovy can be very easily integrated or mixed with Java. The syntax is relatively similar, so the mental switch doesn't hurt too much.

Especialy when used with the Grails framework, Groovy is fun to work with (IMO). I also like the similarity to JavaScript; therefore a project that mixed Groovy on the backend with JavaScript on the client doesn't require understanding two completely different languages; in many cases, it feels more like two dialects of the same language.

share|improve this answer
good points, thanks +1. –  Yar Dec 16 '10 at 21:30
add comment

Regarding Groovy, a Groovy class can certainly do everything that a Java class can, since valid Java is (almost) always valid Groovy.

I've found that Eclipse and NetBeans aren't quite ready for prime-time when it comes to Groovy/Grails development. But IntelliJ is really good, if you have the money.

share|improve this answer
Thanks for that. As I said in the question, I'm NOT interested in Web, so IntelliJ would be free. –  Yar Oct 22 '10 at 18:02
Java isn't quite ALWAYS valid Groovy (but almost), as detailed here (Though somewhat dated): stackoverflow.com/questions/687601/… –  Northover Dec 16 '10 at 9:32
added important qualifier. –  Eric Wilson Dec 16 '10 at 13:59
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.