This is documentation for Mathematica 4, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)
Wolfram Research, Inc.


Welcome to J/Link, a product that integrates Mathematica and Java. J/Link lets you call Java from Mathematica in a completely transparent way, and it also lets you use and control the Mathematica kernel from a 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 Java programmers, J/Link turns Mathematica into a scripting shell that lets you experiment with, build, and test Java classes a line at a time. It also makes Java the ideal language for writing programs that use the computational services of Mathematica.

J/Link's most unique feature is that it lets you load arbitrary Java classes into Mathematica and then create Java objects, call methods, and access fields directly from the Mathematica language. Thus, you can use Mathematica to "script" the functionality of an arbitrary Java program—in effect, writing a Java program in Mathematica. Essentially anything you can do from Java you can now do from Mathematica, perhaps even more easily because you are working in a true interpreted environment.

For example, you can now create a Java-based user interface entirely with Mathematica code. This could be anything from a simple progress bar for a long computation to a dialog box or sophisticated wizard that walks users through a calculation. Such an interface is completely portable and can make full use of AWT, Swing, or any other user-interface class library.

Some uses for J/Link.

Java is a fast, robust, and portable general-purpose programming language. It is not just an "internet" language, although it does have many useful internet features. Java is also emphatically not just a language for writing applets. Applets are a powerful use for Java, but Java is good for much more than that. In fact, applets have already been relegated to a relatively minor category of Java programs. Today, Java is everywhere—on the client, server, browser, database, device, and desktop. And J/Link lets you put Mathematica and Java together in any way you want.

J/Link is designed for end-users and developers alike. The same features that let Mathematica users transparently call any Java method also let developers create sophisticated commercial add-ons to Mathematica. Programmers who want to write custom front ends for Mathematica, or use Mathematica as a computational engine for another program, will find using Java with J/Link is easier than using the traditional MathLink interface from C or C++.

Finally, J/Link comes with full source code. This includes the components written in Mathematica, Java, and C. You can examine the code to supplement the documentation, get tips for your own programs, better understand how to use advanced features, or just see how it works.

Some familiarity with both Java and Mathematica is assumed in this manual. Even if you do not know Java, J/Link is easy to use as a means to call existing Java classes from Mathematica. This only requires learning what classes and methods are available—the syntax and intricacies of the Java language are irrelevant, since you will be writing Mathematica programs, not Java programs.

J/Link and MathLink

The underlying glue that makes this all work is MathLink, Wolfram Research's protocol for sending data and commands back and forth between Mathematica and other programs. At its core, J/Link is a MathLink developer's kit for Java, although it goes far beyond this. In fact, J/Link's best feature is that for a large class of uses, it hides MathLink completely, so users and programmers do not need to know anything about it. This class corresponds to the so-called "installable" or "template" MathLink programs, which plug into Mathematica and extend its functionality. For all types of MathLink programs, J/Link provides a higher-level layer of functionality than the traditional C MathLink programming interface. This makes Java the easiest and most convenient language for writing programs to interact with Mathematica.