Access Java executables and resources directly from the Wolfram Language.

Using Static Methods...

Load the J/Link package

Load the J/Link package using Get (<<):

In[1]:=
Click for copyable input

Launch Java

Launch the local Java runtime with InstallJava:

In[2]:=
Click for copyable input
Out[2]=

Set the class path

Use AddToClassPath to append a file that contains Java classes to the Java class path:

  • By default, AddToClassPath will search relative to $HomeDirectory for files. You can also specify an absolute file path or a directory to search.

Load a class

Load a Java class from the program into the Wolfram kernel using LoadJavaClass:

Out[4]=

Call methods

You can now use static methods and fields in the class directly in computations:

Out[5]=

Using a Class Instance...

Load the J/Link package

Load the J/Link package using Get (<<):

In[6]:=
Click for copyable input

Launch Java

Launch the local Java runtime with InstallJava:

In[7]:=
Click for copyable input
Out[7]=

Set the class path

Use AddToClassPath to append a file that contains Java classes to the Java class path:

  • By default, AddToClassPath will search relative to $HomeDirectory for files. You can also specify an absolute file path or a directory to search.

Create a class instance

Make a new instance of a class using JavaNew:

In[9]:=
Click for copyable input
Out[9]=

Call methods

You can now use methods and fields from this instance directly in computations:

Out[10]=
Notes

For a full explanation of J/Link capabilities, refer to the J/Link User Guide.