Wolfram Computation Meets Knowledge

Wolfram Language & System Documentation Center Wolfram Language Home Page »

J/Link User Guide

Introduction to J/Link

J/Link and WSTP

Calling Java from the Wolfram Language

J/Link Basics

Preamble

Loading the J/Link Package

Launching the Java Runtime

InstallJava
Controlling the Command Used to Launch Java
Overriding the Class Path

Loading Classes

LoadJavaClass
When to Call LoadJavaClass
Contexts and Visibility of Static Members
Inner Classes

Conversion of Types between Java and the Wolfram Language

Creating Objects

Calling Methods and Accessing Fields

Syntax
Underscores in Java Names

Getting Information about Classes and Objects

Quitting or Restarting Java

Version Information

Advanced Topics in J/Link

Controlling the Class Path: How J/Link Finds Classes

The Java Class Path
Overriding the Startup Class Path
Dynamically Modifying the Class Path
Examining the Class Path
Using J/Link's Class Loader Directly

Performance Issues

Overhead of Calls to Java
Speeding Up Sending Large Arrays
An Optimization Example

Reference Counts and Memory Management

Object References in the Wolfram Language
ReleaseJavaObject
JavaBlock
PeekObjects and PeekClasses

Exceptions

How Exceptions Are Handled
The JavaThrow Function

Returning Objects "by Value" and "by Reference"

References and Values
ReturnAsJavaObject
JavaObjectToExpression

MakeJavaObject and MakeJavaExpr

Preamble
MakeJavaObject
MakeJavaExpr

Creating Windows and Other User Interface Elements

Preamble
Interactive and Non-Interactive Interfaces
Modal versus Modeless Operation
Handling Events with Wolfram Language Code: The "MathListener" Classes
Bringing Java Windows to the Foreground
Modal Windows
MathFrame and MathJFrame
Modeless Windows: Sharing the Kernel with Java
Sharing the Front End
Summary of Modal and Modeless Operation
"Manual" Interfaces: The ServiceJava Function
Using a GUI Builder

Drawing and Displaying Wolfram Language Images in Java Windows

The MathCanvas and MathGraphicsJPanel Classes
Showing Wolfram Language Graphics and Typeset Expressions
Drawing Using Java's Graphics Functions
Bitmaps

The Java Console Window

Using JavaBeans

Hosting Applets

Periodical Tasks

Some Special Number Classes

Preamble
The "Wrapper" Classes: Integer, Float, Boolean, and Others
Complex Numbers
BigInteger and BigDecimal

Ragged Arrays

Implementing a Java Interface with Wolfram Language Code

Writing Your Own Installable Java Classes

Preamble
Installable Functions—The Old Way
Installable Functions in Java
Setting Up Definitions in the Wolfram Language When Your Class Is Loaded
Manually Returning a Result to the Wolfram Language
Requesting Evaluations by the Wolfram Language
Throwing Exceptions
Making a Method Interruptible
Writing Your Own Event Handler Code
Debugging Your Java Classes

Deploying Applications That Use J/Link

Coding Tips

Example Programs

Introduction

A Beep Function

Formatting Dates

A Progress Bar

A Simple Modal Input Dialog

A File Chooser Dialog Box

Sharing the Front End: Palette-Type Buttons

Real-Time Algebra: A Mini-Application

GraphicsDlg: Graphics and Typeset Output in a Window

BouncingBalls: Drawing in a Window

Spirograph

A Piano Keyboard

Writing Java Programs That Use the Wolfram Language

Introduction

What Is WSTP?

Overview of the Main J/Link Interfaces and Classes

Preamble

MathLink and KernelLink

MathLinkFactory

MathLinkException

Expr

PacketListener

High-Level User Interface Classes

Sample Program

Creating Links with MathLinkFactory

Using Listen and Connect Modes

Using a Remote Kernel

The MathLink Interface

Managing Links

Packet Functions

Error Handling

Link State

Putting

Getting

Messages

Marks

Complex Class

Yield and Message Handlers

Constants

The KernelLink Interface

Evaluate

Waiting for the Result

The "evaluateTo" Methods

Sending Java Object References

Interrupting, Aborting, and Abandoning Evaluations

Support for PacketListeners

The handlePacket() Method (Advanced Users Only)

Methods Valid Only for "StdLinks"

Sending Computations and Reading Results

WSTP Packets

The WSTP "Packet Loop"

Sending an Evaluation

Reading the Result

The "evaluateTo" Methods

Using the PacketListener Interface

The PacketPrinter Class for Debugging

Using EnterTextPacket

Handling MathLinkExceptions

Graphics and Typeset Output

Preamble

MathCanvas and MathGraphicsJPanel

A Sample Program That Displays Graphics and Typeset Results

evaluateToImage() and evaluateToTypeset()

Aborting and Interrupting Computations

Using Marks

Using Loopback Links

Using Expr Objects

Motivation for the Expr Class

Methods in the MathLink Interface for Reading and Writing Exprs

Exprs as Replacements for Loopback Links

Exprs as a Means to Get String Representations of Expressions

Exprs as Arguments to KernelLink Methods

Examining and Manipulating Exprs

Disposing of Exprs

Threads, Blocking, and Yielding

Sending Object References to the Wolfram Language

Some Special User Interface Classes

Introduction

ConsoleWindow

MathSessionPane

BracketMatcher and SyntaxTokenizer

InterruptDialog

Writing Applets

Top