If you want to compile a simple JAVA program using functionality of the Snifflib library and the linking/building demands of your application are not too complex, a command line approach may be sufficient to meet your needs.
Let's start with a basic hello world program and then build-in the connectivity to the Snifflib library. Open your favorite plain text editor (e.g. jEdit,NEdit etc. ) and enter the following lines. Save the resulting file as HelloSnifflib.java.
/**
Basic hello world program linking to snifflib numerical library.
*/
public class HelloSnifflib
{
public static void main(String[] args)
{
System.out.println("Hello World");
}
}
Now, verify that your command line compilation is working OK by doing the following.
>> javac HelloSnifflib.java
>> java HelloSnifflib
If all goes well no errors or warnings should result from the first line which compiles the code into the file HelloSnifflib.class. After the second command executes, the message Hello World should print to your screen.
Now that you have verified basic java compilation we are ready to verify connectivity with the Snifflib library. Edit the file as follows:
import com.mockturtlesolutions.snifflib.datatypes.DblMatrix;
/**
Basic hello world program linking to snifflib numerical library.
*/
public class HelloSnifflib
{
public static void main(String[] args)
{
System.out.println("Hello World");
DblMatrix X = new DblMatrix("[1 2 3; 4 5 6; 7 8 9]");
X = X.times(DblMatrix.PI);
X.show("Hello Snifflib!");
}
}
The import line serves to includes the DblMatrix class from Snifflib's datatypes package for use in this program. Now, verify your ability to compile against the Snifflib library by doing the following.
Let's assume you are user jdoe and have just downloaded and saved the snifflib-1.7.jar (or latest version) to your home directory.
>> javac -cp .:/home/jdoe/snifflib-1.7.jar HelloSnifflib.java
>> java -cp .:/home/jdoe/snifflib-1.7.jar HelloSnifflib
If all goes well, you should see the following output.
Hello World
[Hello Snifflib!] =
3.142 6.283 9.425
12.566 15.708 18.850
21.991 25.133 28.274