Introduction to J/Link

Welcome to J/Link, a product that integrates the Wolfram Language and Java. J/Link lets you call Java from the Wolfram Language in a completely transparent way, and it also lets you use and control the Wolfram Language kernel from a Java program. For Wolfram Language users, J/Link makes the whole universe of existing and future Java classes an automatic extension to the Wolfram Language environment. For Java programmers, J/Link turns the Wolfram Language 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 the Wolfram Language.

J/Link's most unique feature is that it lets you load arbitrary Java classes into the Wolfram Language and then create Java objects, call methods, and access fields directly from the Wolfram Language. Thus, you can use the Wolfram Language to "script" the functionality of an arbitrary Java programin effect, writing a Java program in the Wolfram Language. Essentially anything you can do from Java you can now do from the Wolfram Language, 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 Wolfram Language 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.

Call Java methods from the Wolfram Language
Write Java programs that use Wolfram System services
Create alternative front ends for the Wolfram Language
Create dialog boxes and other popup user interface elements for Wolfram Language programs
Write applets that use Wolfram Language kernels on the client or server
Write servlets that make Wolfram System services available to HTTP clients

Some uses for J/Link.

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

Finally, J/Link comes with full source code. This includes the components written in the Wolfram Language, 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 the Wolfram Language 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 the Wolfram Language. This only requires learning what classes and methods are availablethe syntax and intricacies of the Java language are irrelevant, since you will be writing Wolfram Language programs, not Java programs.

J/Link and WSTP

The underlying glue that makes this all work is WSTP, Wolfram Research's protocol for sending data and commands back and forth between the Wolfram Language and other programs. At its core, J/Link is a WSTP 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 WSTP completely, so users and programmers do not need to know anything about it. This class corresponds to the so-called "installable" or "template" WSTP programs, which plug into the Wolfram Language and extend its functionality. For all types of WSTP programs, J/Link provides a higher-level layer of functionality than the traditional C WSTP programming interface. This makes Java the easiest and most convenient language for writing programs to interact with the Wolfram Language.