Hi Bill, I would like you to throw some light on the following. 1)if Jython uses both the interpreter and VM , then how does the interpreter and the VM communicate. 2) Can Jython run without the JVM 3)How is dynamic typing and operator overloading supported(is operator overloading the same as C++) 4)where will jython fit in a web-application . 5)How do we glue together a Jython and Java.If it is slower than java then how do we decide when to use jython . Can we a code snippet of Jython+Java and a guideline as to how to run it...
1)if Jython uses both the interpreter and VM , then how does the interpreter and the VM communicate.
All the good tricks are done with reflection.
2) Can Jython run without the JVM
Not normally. If you really want to be out on the edge, there are projects to compile java code to native code that could use on jythonc compiled code. I've never been crazy enough to look into this though
3a)How is dynamic typing (supported)?
Typing is implicit, and happens at runtime. Implicit means that Jython just knows what kind of value your assigning. If there's quotes on something, Jython knows it's a string without you having to give any hints other than the quotes.
and 3b) operator overloading supported(is operator overloading the same as C++)?
Operator loading, similar in principle to implemenations in other languages, uses Python's special class methods to implement. Every class method who's name begins and ends with two underscores, is a "special" method. Operator overloading is done through implementing special methods. Look here for more on special methods.
4)where will jython fit in a web-application.
Jython comes with the class org.python.util.PyServlet which you can place in a servlet container to allow servlets to be written in Jython. Additionally, there is BSF, which will allow Jython code embedded in JSP (as well as other scripting languages). What should be available fairly soon is extensions to the popular MVC development kits like velocity, webmacro, freemarker, that will classes written in jython.
5a)How do we glue together a Jython and Java.
One of two ways. 1. Just use java classes in Jython, i.e. "import java". Jython uses almost most Java classes without modification so not only do you get the glue, it is also hidden behind the scenes. 2. Embed Jython into Java. This is usually done with the class org.python.util.PythonInterpreter. The only trick is to make sure you initialize it with good values for python.home and python.path. Look at org.python.util.PyServlet for the best example of embedding.
5b)If it is slower than java then how do we decide when to use jython.
I bet everybody answers this one differently. There's some places it just makes sense, like embedded interpreters for extending apps, rules engines and report generation. I haven't worked on getting good numbers, but my guess is plan for a 9x speed hit. If that's OK, go with Jython. Speed hits on the total app end up being less than that for me because I habitually recode greedy classes in Java.