The 
Mathematica Journal
Volume 9, Issue 1

Search

In This Issue
Tricks of the Trade
In and Out
Trott's Corner
New Products
New Publications
Calendar
News Bulletins
New Resources
Classifieds

Download This Issue 

About the journal
Editorial Policy
Staff
Submissions
Subscriptions
Advertising
Back Issues
Contact Information

Mathematica 4.2: A Technical Review
Lars Hohmuth

J/Link 2.0

Mathematica 4.2 shipped with a new release of J/Link, the toolkit that integrates Mathematica and has Java pre-installed, thereby avoiding the installation step for all platforms. Using J/Link, you can call Java from Mathematica in a completely transparent way and also control the Mathematica kernel from any Java program.

For Mathematica users, J/Link makes the whole universe of existing and future Java classes an automatic extension to the Mathematica environment. For example, users can use standard Java classes to provide new interfaces to Mathematica or create graphical user interface (GUI) elements using Abstract Window Toolkit (AWT) or Swing classes.

For Java programmers, J/Link turns Mathematica into a scripting shell that allows them to experiment with, build, and test Java classes one line at a time. It also makes Java a powerful language for writing programs that use the computational services of Mathematica.

Mathematica 4.2 includes J/Link and JRE Version 1.4 on Windows, Linux, and Solaris and the JRE Version 1.3.1 on most other platforms. This means that you can start using J/Link right out of the box. Mathematica developers can now also rely on a JRE for applications that mix Mathematica and Java functionality. Let us look at a simple example.

This loads the J/Link package.

This launches the Java runtime and prepares it for use.

This constructs a new object of the specified class.

Functions in this Java class can then be called from Mathematica.

J/Link 2.0 has a number of enhancements over previous versions of J/Link, including the following.

  • JLink.jar was moved to the JLink directory, from JLink/SystemAdditions.
  • There were dramatic speed improvements for calling Java methods.
  • A new component called com.wolfram.jlink.ui.MathSessionPane implements a complete In/Out session window, but with many more features.
  • A new component called MathGraphicsJPanel displays Mathematica graphics and typeset expressions.
  • The JavaBlock function is improved to give it more control over what objects are released when it ends. These improvements make some common programming idioms easier, without having to resort to manual use of ReleaseObject.
  • A new KeepObjects option added to JavaBlock allows you to specify a list of objects that will not be released at the end.
  • The new ImplementInterface function lets you implement any Java interface entirely with Mathematica code.
  • A new SetInternetProxy function allows users to specify proxy port and host information if necessary to reach the internet.
  • A new MakeJavaExpr function lets you construct, from Mathematica, a Java expr object from an arbitrary Mathematica expression.
  • A new JLink`Information` context defines symbols giving version information.
  • For Java programmers, the MLGetType and MLGetNext methods, when applied to a KernelLink object, can now return KernelLink.MLTKOBJECT. This means that the expression on the link is a Java object reference and can be read with getObject.
  • The MathLink connect method takes an optional timeout parameter giving the number of milliseconds to wait for the connection before throwing an exception.
  • Information can be sent to the Java Console.

See the article by Todd Gayley in this issue for information on building user interfaces using J/Link. Additional examples and information about J/Link are available on the Wolfram Research website at www.wolfram.com/solutions/mathlink/jlink.



     
About Mathematica  Download Mathematica Player
Copyright © Wolfram Media, Inc. All rights reserved.