MattS
MattS

Reputation: 727

Proper syntax for "if" statement in J/Link

When writing in Java within Mathematica (using J/Link), do I use Java or Mathematica syntax for an If-Then statement?

This question is not about any particular code. The answer should be the same, regardless of the code being used. I know how to write using either syntax, I just don't know which one to use.

Upvotes: 0

Views: 248

Answers (1)

Jonie Shih
Jonie Shih

Reputation: 252

You can't really write java inside Mathematica. J/Link simply allows you to call Java functions via Mathematica and manipulate Mathematica objects-created based on Java objects. (http://reference.wolfram.com/mathematica/JLink/tutorial/CallingJavaFromMathematica.html#15615)

Hence you'll be writing if statements in Mathematica syntax. If[condition, t, f]

On a side note, the other side of J/Link allows you to use Mathematica from Java. Likewise you'll be writing java there in the majority of your code and calling something along the lines of ml.Evaluate("If[condition, t, f]") if you need to compute using Mathematica. For anyone interested, .NET/Link works the same.

Upvotes: 2

Related Questions