1 / 22

JLink

JLink. Linking Mathematica with Java and the other way round…. Outline. Introduction Calling Java from Mathematica Using Mathematica Kernel in Java applications. Mathematica calls. Notebook front end. MathLink. Mathematica Kernel. Mathematica calls using Java.

ltavarez
Download Presentation

JLink

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. JLink Linking Mathematica with Java and the other way round…

  2. Outline • Introduction • Calling Java from Mathematica • Using Mathematica Kernel in Java applications

  3. Mathematica calls Notebook front end MathLink Mathematica Kernel

  4. Mathematica calls using Java Notebook front end JLink MathLink MathLink Mathematica Kernel Java Runtime

  5. Java App using Mathematica Kernel Java App JLink MathLink Mathematica Kernel

  6. Introduction • JLink uses MathLink in its core and tries to hide it from user • Allow users to (include Java in Mathematica): • Call Java methods from Mathematica • Create alternative front-ends for Mathematica • Create dialog boxes and other popup user interface elements for Mathematica programms

  7. Introduction • Allow users to (include Mathematica in Java): • Write Java programs that uses Mathematica services • Write applets that use Mathematica Kernels on the client server • Write servlets that make Mathematica services available to HTTP clients

  8. Calling Java from Mathematica Load the JLink package: Launching the Java Runtime:

  9. Calling Java from Mathematica Loading a class: Creating objects: or

  10. Calling Java from Mathematica Creating objects with JavaNew[] JavaNew[] returns a reference to the object All the data (fields) stay to the Java side That makes its call, fast Except: the times that is more convenient to be returned “by value”, that means the times that there is a corresponding type between the two languages

  11. Calling Java from Mathematica Conversion of types between Java and Mathematica:

  12. Calling Java from Mathematica Calling methods and accessing fields:

  13. Calling Java from Mathematica Releasing the reference to the objects Must tell Mathematica (if needed) that the JavaObject is no longer used

  14. Calling Java from Mathematica JavaBlocks Pretty much as C functions, do the job, return an object, release any temporary data used

  15. Calling Java from Mathematica Exceptions are handled by JLink automatically If an uncaught exception is thrown in the Java side, a message will be printed in Mathematica

  16. Calling Java from Mathematica Creating windows “Modal” window: the Mathematica kernel waits for the window to be dismissed (input dialog) DoModal[] / EndModal[] SetModal[] (for MathFrames) “Modeless” window: the Mathematica kernel is shared between the frond end notebook and the window (a window that allows user to load packages) ShareKernel[] / UnshareKernel[] (default for Mathematica releases after 5.1) ShareFrontEnd[] / UnshareFrontEnd[]

  17. Using Mathematica kernel in Java applications Import the JLink.jar MathLink Interface The root of all link objects in JLink KernelLink Interface Extends MathLink Makes the assumption that the other side of the link isa Mathematica Kernel

  18. Calling Java from Mathematica Creating Links with MathLinkFactory createMathLink() (connect with other than Mathematica Kernel) createKernelLink(String cmdLine) createKernelLink(String[] argv) all return the link object or throw MathLinkException

  19. Using Mathematica kernel in Java applications Asking for evaluation MathLink: void put(arg) throws MathLinkException different types of arg: int, long, double, String, boolean, Object void putFunction(String f, int argCount) throws MathLinkException int getInteger(), long getLongInteger(), etc... All throw MathLinkExcetion All public

  20. Using Mathematica kernel in Java applications Asking for evaluation KernelLink: void evaluate(String or expr) throws MathLinkException void waitForAnswer() throws MathKernelException void disgardAnswer() throws MathLinkException “evaluateTo” methods No need to call waitForAnswer() or disgardAnswer() Doesn't throw any Exception Instead, returns null if there is an error

  21. Using Mathematica kernel in Java applications Asking for evaluation KernelLink:

  22. Conclusion JLink is a high-level protocol (based on MathLink)to make easier the communication between Mathematica and Java Works both ways for more informations visit: http://reference.wolfram.com/mathematica/JLink/tutorial/Overview.html

More Related