By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,034 Members | 1,325 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,034 IT Pros & Developers. It's quick & easy.

Integration with java

P: n/a
Hello,

I am working on a project in Python, and I"m
currently
looking into the possibiliy of writing some of the
project"s modules in Java. Given that a large part of
the code is already written in Python, using the
standard libraries and several extension modules, I
am
trying to gauge the viability of integration with
Java
via Jython with minimal impact on present code, on
the
complexity of future code, and on deadlines!

I need to know in general how dirty it will be to
combine the two languages, and what the costs I
should
take into account are. I"m also interested to know if
there are any commonly accepted strategies to fully
switch project languages (I"m considering, in the
extreme case, to change it all into Java), and if
writing some modules in Java and replacing the rest
gradually makes sense.

Three more specific questions I thought of:
1. Is is possible to pack a Jython/Java program in a
py2exe-like fashion? Is it possible to pack in such a
way both Python, Jython and Java code?
2. Does transferring large data structures between
Java and Python code running by Jython have a
significant effect on memory? For example, would
passing the result of a large database query from
Java
to Jython, for further processing, cause the entire
data to be duplicated or something similar?
3. Did I miss anything fundemental?

Thanks!

Joe.
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Jul 18 '05 #1
Share this Question
Share on Google+
14 Replies


P: n/a
Joachim Boomberschloss wrote:
the code is already written in Python, using the
standard libraries and several extension modules


One thing to keep in mind is that Jython does not
integrate CPython, instead it "understands" python code
directly. So if you have a C extension that works with python
it won't work with Jython.

My feeling is that if you had a lot of Java code written and
wanted to build on that with python Jython would be a better
fit than vice versa.

Istvan.
Jul 18 '05 #2

P: n/a
It is possible, though possibly painful, to call java modules from
CPython using JNI. This is more difficult than Jython integration, but
probably required if you want to keep using your extension modules.

The JNI tutorial is available at
http://java.sun.com/docs/books/tutor...1.1/index.html .

I probably would not take this approach unless java offered some
incredibly substantial benefit or I was integrating a complex python
system with a complex java sytem. I would also probably start by
creating a good C API to access the required java modules via JNI and
then use SWIG (http://www.swig.org/) to generate the python wrapper.

Of course if you can drop the extension modules you have already
written, accessing Java from Jython is just an import statement away.
Good luck,

Chris

Jul 18 '05 #3

P: n/a
How about this?
http://jpype.sourceforge.net/

(I haven't used it myself)

Jul 18 '05 #4

P: n/a
In article <sP********************@giganews.com>,
Istvan Albert <ia*****@mailblocks.com> wrote:
Joachim Boomberschloss wrote:
the code is already written in Python, using the
standard libraries and several extension modules


One thing to keep in mind is that Jython does not
integrate CPython, instead it "understands" python code
directly. So if you have a C extension that works with python
it won't work with Jython.

My feeling is that if you had a lot of Java code written and
wanted to build on that with python Jython would be a better
fit than vice versa.

Istvan.


There are other possibilities, though, including JPE
<URL: http://jpe.sourceforge.net >. I recommend the
original poster consider the latter.
Jul 18 '05 #5

P: n/a
Can someone summarize in a nutshell what is the
difference between JPype and JPE?
Jul 18 '05 #6

P: n/a
In article <34*************@individual.net>,
Jon Perez <jb********@wahoo.com> wrote:
Can someone summarize in a nutshell what is the
difference between JPype and JPE?


JPE's the original. It provided more functionality than JPype has
achieved so far, I believe (though that could change any day). I
think no one now maintains JPE.

Someone really ought to include a couple of sentences to that effect
on the front page of <URL: http://jpype.sf.net/ >.
Jul 18 '05 #7

P: n/a
Cameron Laird wrote:
In article <34*************@individual.net>,
Jon Perez <jb********@wahoo.com> wrote:
Can someone summarize in a nutshell what is the
difference between JPype and JPE?

JPE's the original. It provided more functionality than JPype has
achieved so far, I believe (though that could change any day). I
think no one now maintains JPE.

Someone really ought to include a couple of sentences to that effect
on the front page of <URL: http://jpype.sf.net/ >.


Well, Cameron summed it up pretty good :)

I'd add that The only major (and yes I know it is VERY major)
funtionailty missing in JPype is the ability to subclass Java classes in
Python.

On the other hand JPype will (soon) have functionality that JPE doesnt
have. Java arrays can already (in 0.4) be iterated as regular Python
collections. Version 0.5 will add that same behavior for Java
collections (Map, List, Set, Iterator).

Of course, the above is based on the JPE documentation, because I havent
been able to get JPE to work.

About Cameron's suggestion, sure. I'll do it as soon as I (or someone
else) can get both JPype and JPE to work so they can be compared through
more than just their respective documentation.

Steve
a.k.a devilwolf on sourceforge
Jul 18 '05 #8

P: n/a
Cameron Laird wrote:
Someone really ought to include a couple of sentences to that effect
on the front page of <URL: http://jpype.sf.net/ >.


Now I remember visiting this site, but never understood how it
actually worked. Examples such as:

from jpype import *
startJVM("d:/tools/j2sdk/jre/bin/client/jvm.dll", "-ea")
java.lang.System.out.println("hello world")
shutdownJVM()

in three different versions are the only code examples
that to show "complete" working snippets. I'm still
clueless as to how would one say share a list between
python and java.

Istvan.
Jul 18 '05 #9

P: n/a
Istvan Albert wrote:
Now I remember visiting this site, but never understood how it
actually worked. Examples such as:

from jpype import *
startJVM("d:/tools/j2sdk/jre/bin/client/jvm.dll", "-ea")
java.lang.System.out.println("hello world")
shutdownJVM()

in three different versions are the only code examples
that to show "complete" working snippets. I'm still
clueless as to how would one say share a list between
python and java.


A while ago there was a thread in c.l.p about using JPype to access JMS
from within Python. IIRC someone then contributed a more elaborate real
life example of how to do this. Search Google Groups for more details.

Regards,
Jan
Jul 18 '05 #10

P: n/a
Istvan Albert wrote:
Cameron Laird wrote:
Someone really ought to include a couple of sentences to that effect
on the front page of <URL: http://jpype.sf.net/ >.

Now I remember visiting this site, but never understood how it
actually worked. Examples such as:

from jpype import *
startJVM("d:/tools/j2sdk/jre/bin/client/jvm.dll", "-ea")
java.lang.System.out.println("hello world")
shutdownJVM()

in three different versions are the only code examples
that to show "complete" working snippets. I'm still
clueless as to how would one say share a list between
python and java.

Istvan.


I am sorry you find the site so confusing ... perhpas I shold post a
more complete example in a prominent location ...

To asnwer your question more fully, the jpype-specific cide is only for
looking up the Classes and startting/stopping the environment. For
everything else, Java objects and classes are used as regular Python
objects.

In version 0.4.x, the API mostly remain Java's. This means some of the
basic magic python methods have been mapped to java equivalent (like
__str__ mapped to toString() and __eq__ mapped to equals()).

If you have any questions, feel free to post them on the feedback list
on sourceforge. I check it every day and I try to answer as quickly as
possible.

Steve, aka devilwolf on sourceforge, maintainer of JPype
Jul 18 '05 #11

P: n/a
Istvan Albert wrote:
Joachim Boomberschloss wrote:
the code is already written in Python, using the
standard libraries and several extension modules
One thing to keep in mind is that Jython does not
integrate CPython, instead it "understands" python code
directly. So if you have a C extension that works with python
it won't work with Jython.


Also, Jython is several versions behind CPython, so any Python code
that uses generators or new-style division won't work either.
My feeling is that if you had a lot of Java code written and
wanted to build on that with python Jython would be a better
fit than vice versa.


I agree.

Jul 18 '05 #12

P: n/a
Dan Bishop wrote:
Istvan Albert wrote:
Joachim Boomberschloss wrote:

the code is already written in Python, using the
standard libraries and several extension modules


One thing to keep in mind is that Jython does not
integrate CPython, instead it "understands" python code
directly. So if you have a C extension that works with python
it won't work with Jython.

Also, Jython is several versions behind CPython, so any Python code
that uses generators or new-style division won't work either.

My feeling is that if you had a lot of Java code written and
wanted to build on that with python Jython would be a better
fit than vice versa.

I agree.

Also let's not forget that the PSF has funded a project that's intended
to help Jython get up to the curve - see
http://www.python.org/psf/grants/Jyt...t_Proposal.pdf. If that
project succeeds, and if 2.5 development *does* focus mostly on the
library, there's a sporting chance that Jython can be fully up to date
for the 2.5 release.

regards
Steve
--
Steve Holden http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/
Holden Web LLC +1 703 861 4237 +1 800 494 3119
Jul 18 '05 #13

P: n/a
Steve Menard wrote:
To asnwer your question more fully, the jpype-specific cide is only for
looking up the Classes and startting/stopping the environment. For
everything else, Java objects and classes are used as regular Python
objects.
Thanks for the response. Currently I don't need to use java but
in the past when I explored such a possibility I looked at jpype
and I was unable to understand from the documentation what it
actually does.

There is a lot of text there, but it is all concerning catching
errors or other subtleties. For a new visitor the most important
question is about how it works, what does it do, and how can it be
applied for the given problem.
everything else, Java objects and classes are used as regular Python
objects.


This is too generic. My question was a little more specific,
how would I pass a python list as an argument of a java class/method or
transform a java list into a python one? You don't have to
answer it here, I'm just pointing out the kind of
questions that I was unable to get an answer for on the jpype
website.

best,

Istvan.
Jul 18 '05 #14

P: n/a
Istvan Albert wrote:
Steve Menard wrote:
To asnwer your question more fully, the jpype-specific cide is only
for looking up the Classes and startting/stopping the environment. For
everything else, Java objects and classes are used as regular Python
objects.

Thanks for the response. Currently I don't need to use java but
in the past when I explored such a possibility I looked at jpype
and I was unable to understand from the documentation what it
actually does.

There is a lot of text there, but it is all concerning catching
errors or other subtleties. For a new visitor the most important
question is about how it works, what does it do, and how can it be
applied for the given problem.
> everything else, Java objects and classes are used as regular Python
> objects.


This is too generic. My question was a little more specific,
how would I pass a python list as an argument of a java class/method or
transform a java list into a python one? You don't have to
answer it here, I'm just pointing out the kind of
questions that I was unable to get an answer for on the jpype
website.

best,

Istvan.


I see what you mean. And I agree fully. I guess that's one more thing to
put on the TODO list hehe.

Thanks for the input.
Steve
Jul 18 '05 #15

This discussion thread is closed

Replies have been disabled for this discussion.