Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am very interested in Python for programming on the JVM, and I\'ve worked in J

ID: 639517 • Letter: I

Question

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.

Explanation / Answer

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.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote