java interface

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

java interface

Gilbert Peffer
What are the steps one has to take in order to interface Java with the
QuantLib C++ code? One method is through JNI (as far as I understood it),
but I think the other is through Python using the SWIG stuff. Since I have
no experience in either of them, could anybody give me some hints regarding
the procedure to call classes from a Java interface.
Cheers, Gilbert



Reply | Threaded
Open this post in threaded view
|

Re: java interface

Luigi Ballabio-3
At 07:40 PM 7/9/01 +0200, Gilbert Peffer wrote:
>What are the steps one has to take in order to interface Java with the
>QuantLib C++ code? One method is through JNI (as far as I understood it),
>but I think the other is through Python using the SWIG stuff.

Hi Gilbert,
         I think you meant Jython - I don't know of other mainstream
methods of interfacing Python and Java. Unfortunately, Jython can only
import pure Python modules or Java classes, but not C/C++ Python
extensions, so we're left in the cold there.

The only way out - apart from high-level protocols like CORBA, but somehow
I don't think that you want to write a C++ servant and a Java client first
thing in the morning - seems to be JNI.

SWIG used to have some Java support which was recently broken and is going
to be reintroduced in release 1.3.6, due any day. I was about to take a
look to the release candidate right now.

We also thought of interfacing QL with Java through SWIG, but there was an
issue which made it a painful experience, namely, C++ objects allocated on
the heap by the constructor of the Java shadow object should be deallocated
in its finalize() method. Unfortunately, finalize() is not guaranteed to be
called upon destruction. This leads either to possible memory leaks or to
having to manually call finalize() or some other delete() method whenever a
QuantLib object goes out of scope.

So thoughtful of the Java designers, but then again, I suppose that from
day 1 JNI was designed to discourage developers from using it and have them
go 100% Java instead...

But enough with the rambling. The bottom line is: I'll have a look at the
new SWIG release and report faithfully to the list.

Bye for now,
                 Luigi



Reply | Threaded
Open this post in threaded view
|

RE: java interface

Gilbert Peffer
I was told that if you can't interface C++ from within a Java applet, or at
least that the applet won't work. Does anybody know anything about this?
Cheers, Gilbert

>-----Mensaje original-----
>De: [hidden email]
>[mailto:[hidden email]]En nombre de Luigi
>Ballabio
>Enviado el: 10 July 2001 11:50
>Para: Gilbert Peffer; QuantLibUsers
>Asunto: Re: [Quantlib-users] java interface
>
>
>At 07:40 PM 7/9/01 +0200, Gilbert Peffer wrote:
>>What are the steps one has to take in order to interface Java with the
>>QuantLib C++ code? One method is through JNI (as far as I understood it),
>>but I think the other is through Python using the SWIG stuff.
>
>Hi Gilbert,
>         I think you meant Jython - I don't know of other mainstream
>methods of interfacing Python and Java. Unfortunately, Jython can only
>import pure Python modules or Java classes, but not C/C++ Python
>extensions, so we're left in the cold there.
>
>The only way out - apart from high-level protocols like CORBA, but somehow
>I don't think that you want to write a C++ servant and a Java client first
>thing in the morning - seems to be JNI.
>
>SWIG used to have some Java support which was recently broken and is going
>to be reintroduced in release 1.3.6, due any day. I was about to take a
>look to the release candidate right now.
>
>We also thought of interfacing QL with Java through SWIG, but there was an
>issue which made it a painful experience, namely, C++ objects allocated on
>the heap by the constructor of the Java shadow object should be
>deallocated
>in its finalize() method. Unfortunately, finalize() is not
>guaranteed to be
>called upon destruction. This leads either to possible memory leaks or to
>having to manually call finalize() or some other delete() method
>whenever a
>QuantLib object goes out of scope.
>
>So thoughtful of the Java designers, but then again, I suppose that from
>day 1 JNI was designed to discourage developers from using it and
>have them
>go 100% Java instead...
>
>But enough with the rambling. The bottom line is: I'll have a look at the
>new SWIG release and report faithfully to the list.
>
>Bye for now,
>                 Luigi
>
>
>_______________________________________________
>Quantlib-users mailing list
>[hidden email]
>http://lists.sourceforge.net/lists/listinfo/quantlib-users
>



Reply | Threaded
Open this post in threaded view
|

RE: java interface

Luigi Ballabio-3
Hi all,
         news from the SWIG side: release 1.3.6 is sound and can be used to
create useable Java interfaces. As soon as it is actually released, and if
there is any interest from anyone, we could spin off a QuantLib-Java module
parallel to QuantLib-Python and QuantLib-Ruby.

On to Gilbert's question (by the way, how do you pronounce your name? The
english way? The french way? Some other way?):

At 11:59 AM 7/10/01 +0200, Gilbert Peffer wrote:
>I was told that if you can't interface C++ from within a Java applet, or at
>least that the applet won't work. Does anybody know anything about this?

Well, an applet is downloaded and executed client-side in the browser
virtual machine. The browser will not download and load a C++ shared
library to go with the applet - besides mere reasons of portability of the
compiled code, an applet has strong security restrictions which make it
impossible to execute non-Java code. The VM has no means to know what the
C++ code does (it could format your disk and such), so it does the safe
thing and stays away from it.

What you can do is to use a servlet instead, which is executed server-side
and dynamically generates HTML to be sent to the browser. You can compile
and install the C++ extension on the web server where the servlet runs, and
it will be loaded and work its magic.

Bye,
         Luigi


-----------------------------------------------------
In case you found the label [Mail virus free] in the subject of this mail,
that is only because I forgot to remove it before replying.
The label was added by our new internet provider - they want to make the
point that they practice safe mailing. Of course we all know that there is
no such thing, therefore you can happily disregard it.



Reply | Threaded
Open this post in threaded view
|

RE: java interface

Gilbert Peffer
Hi Luigi
>
>Hi all,
>         news from the SWIG side: release 1.3.6 is sound and can
>be used to
>create useable Java interfaces. As soon as it is actually released, and if
>there is any interest from anyone, we could spin off a
>QuantLib-Java module
>parallel to QuantLib-Python and QuantLib-Ruby.

Yes, I am planning to use the QuantLib library to implement a course on PDEs
in Finance (ideally accessible through Internet) ...

>
>On to Gilbert's question (by the way, how do you pronounce your name? The
>english way? The french way? Some other way?):

The French way, since I'm from Luxembourg :-)

>
>At 11:59 AM 7/10/01 +0200, Gilbert Peffer wrote:
>>I was told that if you can't interface C++ from within a Java
>applet, or at
>>least that the applet won't work. Does anybody know anything about this?
>
>Well, an applet is downloaded and executed client-side in the browser
>virtual machine. The browser will not download and load a C++ shared
>library to go with the applet - besides mere reasons of portability of the
>compiled code, an applet has strong security restrictions which make it
>impossible to execute non-Java code. The VM has no means to know what the
>C++ code does (it could format your disk and such), so it does the safe
>thing and stays away from it.
>
>What you can do is to use a servlet instead, which is executed server-side
>and dynamically generates HTML to be sent to the browser. You can compile
>and install the C++ extension on the web server where the servlet
>runs, and
>it will be loaded and work its magic.

Yes, you are absolutely right about the security stuff. Sorry, I'm kind of
new to that stuff (sniff!). I'll have a look at the servlet stuff.

Thanks a lot, Gilbert



Reply | Threaded
Open this post in threaded view
|

RE: java interface [Mail virus free]

Luigi Ballabio-3
At 04:09 PM 7/10/01 +0200, Gilbert Peffer wrote:
>Yes, I am planning to use the QuantLib library to implement a course on PDEs
>in Finance (ideally accessible through Internet) ...

Great. Just a thought: Java is very much hyped as the Internet language,
but once you decide to keep your calculations server-side, a CGI in Python
could be just as good. However, I think a Java module is a thing we can
consider.

Bye,
         Luigi



-----------------------------------------------------
In case you found the label [Mail virus free] in the subject of this mail,
that is only because I forgot to remove it before replying.
The label was added by our new internet provider - they want to make the
point that they practice safe mailing. Of course we all know that there is
no such thing, therefore you can happily disregard it.