HoriAsso - Documentation: Difference between revisions

From Drorbn
Jump to navigationJump to search
Line 10: Line 10:
*Download JRE 5.0 Update 6 (or the latest version) from [http://java.sun.com/j2se/1.5.0/download.js Sun] and install it following instructions from the official [http://java.sun.com/j2se/1.5.0/install.html Setup Documentation].
*Download JRE 5.0 Update 6 (or the latest version) from [http://java.sun.com/j2se/1.5.0/download.js Sun] and install it following instructions from the official [http://java.sun.com/j2se/1.5.0/install.html Setup Documentation].


==How to start using Jlink in a Mathematica notebook==
==How to start using ''Jlink'' in a ''Mathematica'' notebook==
*Write the Java source code (.java files) and compile it using the command "javac file.java." Place the compiled files (.class files) in the directory you want. (I have not tried to make .jar files yet so I will not write about it here)
*Write the Java source code (''.java'' files) and compile it using the command
javac file.java
Place the compiled files (''.class'' files) in the directory you want. (I have not tried to make .jar files yet so I will not write about it here)


*Open a ''Mathematica'' notebook, install Jlink by writing:
*Open a ''Mathematica'' notebook, install Jlink by writing:
Line 20: Line 22:
or to use a specific java runtime if you have more than one installed on your computer, write:
or to use a specific java runtime if you have more than one installed on your computer, write:
InstallJava[commandLine->"/wherever/java/is"] in Linux
InstallJava[commandLine->"/wherever/java/is"] in Linux
InstallJava[CommandLine -> "d:\\\\path\\to\\java.exe"] in Windows.
InstallJava[CommandLine -> "d:\\\\path\\to\\java.exe"] in Windows


*Add the directory which contains the compiled java (.class) files to the class path, ie, where Java will look for class files, by writing
*Add the directory which contains the compiled java (.class) files to the class path, ie, where Java will look for class files, by writing
AddToClassPath["wherever/my/class/files/are"] in Linux
AddToClassPath["wherever/my/class/files/are"] in Linux
AddToClassPath["c:\\my\\java\\dir"] in Windows
AddToClassPath["c:\\my\\java\\dir"] in Windows




*Load the Java classes by writing
*Load the Java classes by writing
LoadJavaClass["Classname1"]
LoadJavaClass["Classname1"]
LoadJavaClass["Classname2"]
LoadJavaClass["Classname2"]




*Create New Java Objects by writing
*Create New Java Objects by writing
JavaNew["classname1",constructorArg1,constructorArg2...]
JavaNew["classname1",constructorArg1,constructorArg2...]




*Access the non-static methods and variables of any object the same way you would in Java except replace "." (java) by "@" (Mathematica) and "()" (Java) by "[]" (Mathematica). Access static methods or variables by replacing "." in Java by "`" in Mathematica. (I haven't used this yet so I am not entirely sure.)
*Access the non-static methods and variables of any object the same way you would in Java except replace "'''.'''" (''java'') by "'''@'''" (''Mathematica'') and "'''()'''" (''Java'') by "'''[]'''" (''Mathematica''). Access static methods or variables by replacing "'''.'''" in ''Java'' by "'''`'''" in ''Mathematica''. (I haven't used the static methods yet so I am not entirely sure.)


*For detailed documentation on JLink, please consult the Jlink manual in the Mathematica Help Browser.
*For detailed documentation on ''JLink'', please consult the ''Jlink'' manual in the ''Mathematica'' Help Browser.

Revision as of 12:22, 3 June 2006

In this project, we will be mainly using Commands in Mathematica to access Java programs that we write. Here is how to set up the system:

How to set up a system for using Java in Mathematica

How to install Mathematica, J/Link, and Java

  • Jlink is already completely installed in Mathematica 4.2 and later. If you are using earlier versions of Mathematica, you can install JLink following instructions on the official Jlink Setup Documentation.
  • Download JRE 5.0 Update 6 (or the latest version) from Sun and install it following instructions from the official Setup Documentation.

How to start using Jlink in a Mathematica notebook

  • Write the Java source code (.java files) and compile it using the command
javac file.java

Place the compiled files (.class files) in the directory you want. (I have not tried to make .jar files yet so I will not write about it here)

  • Open a Mathematica notebook, install Jlink by writing:
Needs["JLink`"] 
  • Install Java by writing:
InstallJava[] 

or to use a specific java runtime if you have more than one installed on your computer, write:

InstallJava[commandLine->"/wherever/java/is"] in Linux
InstallJava[CommandLine -> "d:\\\\path\\to\\java.exe"] in Windows 
  • Add the directory which contains the compiled java (.class) files to the class path, ie, where Java will look for class files, by writing
AddToClassPath["wherever/my/class/files/are"] in Linux
AddToClassPath["c:\\my\\java\\dir"] in Windows


  • Load the Java classes by writing
LoadJavaClass["Classname1"]
LoadJavaClass["Classname2"]


  • Create New Java Objects by writing
JavaNew["classname1",constructorArg1,constructorArg2...]


  • Access the non-static methods and variables of any object the same way you would in Java except replace "." (java) by "@" (Mathematica) and "()" (Java) by "[]" (Mathematica). Access static methods or variables by replacing "." in Java by "`" in Mathematica. (I haven't used the static methods yet so I am not entirely sure.)
  • For detailed documentation on JLink, please consult the Jlink manual in the Mathematica Help Browser.