HoriAsso - Documentation: Difference between revisions
From Drorbn
Jump to navigationJump to search
Line 17: | Line 17: | ||
*For detailed documentation on ''JLink'', please consult the ''Jlink'' manual in the ''Mathematica'' Help Browser. The following are extracted from there. |
*For detailed documentation on ''JLink'', please consult the ''Jlink'' manual in the ''Mathematica'' Help Browser. The following are extracted from there. |
||
*Open a ''Mathematica'' notebook, install ''JLink'' by writing: |
*Open a ''Mathematica'' notebook, install ''JLink'' by (writing and executing): |
||
Needs["JLink`"] |
Needs["JLink`"] |
||
*Install ''Java'' by |
*Install ''Java'' by: |
||
InstallJava[] |
InstallJava[] |
||
or to use a specific java runtime if you have more than one installed on your computer |
or to use a specific java runtime if you have more than one installed on your computer: |
||
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 |
*Add the directory which contains the compiled java (.class) files to the class path, ie, where Java will look for class files, by |
||
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 |
*Load the Java classes by |
||
LoadJavaClass["Classname1"] |
LoadJavaClass["Classname1"] |
||
LoadJavaClass["Classname2"] |
LoadJavaClass["Classname2"] |
||
*Create New Java Objects by |
*Create New Java Objects by |
||
JavaNew["classname1",constructorArg1,constructorArg2...] |
JavaNew["classname1",constructorArg1,constructorArg2...] |
||
Revision as of 11:39, 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
- Install Mathematica following the official instructions.
- Jlink is already completely installed in Mathematica 4.2 and later. If you are using earlier versions of Mathematica, you can install JLink following the official instructions.
- Download JRE 5.0 Update 6 (latest as of June 2006) the latest version from Sun and install it following the official official instructions.
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)
- For detailed documentation on JLink, please consult the Jlink manual in the Mathematica Help Browser. The following are extracted from there.
- Open a Mathematica notebook, install JLink by (writing and executing):
Needs["JLink`"]
- Install Java by:
InstallJava[]
or to use a specific java runtime if you have more than one installed on your computer:
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
AddToClassPath["wherever/my/class/files/are"] in Linux AddToClassPath["c:\\my\\java\\dir"] in Windows
- Load the Java classes by
LoadJavaClass["Classname1"] LoadJavaClass["Classname2"]
- Create New Java Objects by
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.)