HoriAsso - Documentation: Difference between revisions
From Drorbn
Jump to navigationJump to search
Line 15: | Line 15: | ||
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) |
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 |
*Open a ''Mathematica'' notebook, install ''JLink'' by writing: |
||
Needs["JLink`"] |
Needs["JLink`"] |
||
*Install Java by writing: |
*Install ''Java'' by writing: |
||
InstallJava[] |
InstallJava[] |
||
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: |
Revision as of 11:27, 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)
- 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.