JXN versus Java
no compilation
- JXN runs Java statements without compilation
- commands entered into the input field are processed immedeately → REPL (read-eval-print-loop)
- jxn script files (see JxnScripting)
- commands in a script file are processed in sequence
- by default processing terminates after the first exception (see how to change the error handling)
no variable declarations
- variables are automatically declared by assignment
- 'overwrites' warning, if a variable is reassigned with an object of different type
(primitive variables are reassigned with different type primitive values without warning)
- runtime type is shown in output
- variables are global by default,
$name
defines a lokal variable visible only within an included jxn file or a jxn function
simplified syntax
- see also JxnSimplifiedSyntaxTable
- * operator may be omitted:
a b ≡ a * b
- function calls with exactly one parameter may be written without brackets:
sqrt x ≡ sqrt(x)
- ^ operator:
x^y
or alternatively x**y
stands for pow(x,y)
(see missing java operators)
- @ is used instead of the
new
operator in java (don't confuse with java annotations which are not supported by jxn)
- automatically searches class
JxnUtilities
and
class java.lang.Math
for static methods:
e.g. sqrt 3.
finds java.lang.Math.sqrt(3.)
- static method calls on the class of the first non primitive argument (if the class is not explicitly specified):
e.g. sqrt j
calls JxnComplexAlgebra.sqrt(j)
no type cast necessary for object references
- method invocation with automatic method matching according to the runtime type of the arguments
- auto toString (on method invocation)
if no other signature fits for the given argument(s) and a method signature contains one or
more parameters of type java.lang.String
the respective argument(s) is(are) automatically converted to String
via "" + argument
(Note: Since an argument of any type fits for a parameter of type java.lang.Object
,
a signature with an Object parameter inhibits auto toString for the respective argument)
controlled type cast for primitive values
- intelligent method matching with automatic type cast of arguments
- JXN supports automatic upcast and controlled downcast of arguments on method invocation
- upcast = widening cast (implicit)
byte -> short -> int -> long -> float -> double
char -> int -> ...
- downcast = narrowing cast (possible loss of significance due to overflow)
=> in java only explicit, in jxn also implicit, but only if the cast is possible without overflow for the given value
- also supported in JXN:
char -> short
and
short -> char
as well as
boolean -> ...
and
... -> boolean
explicit primitive value type cast (see also class JxnCast
):
- for
type: double, float, long, int, short, byte, character, boolean
- Java:
(type)value
is replaced by
- JXN:
JxnCast.toType(value)
or
(value).typeValue()
exceptions are handled automatically
- In interactive mode method calls which may throw exceptions need no special handling (
try ... catch ...
processed internally)
- script processing by default terminates after the first exception
- to change the error handling and continue the script after exceptions insert setAbort(false)
in the jxn-file
before the first possible exception:
oldDebug = $this.setAbort(false)
:
: commands to be executed without abort
:
$this.setDebug(oldDebug) ! restores the original error handling
- or to continue after an exception in a single command execute the command like this:
$this.test( "command" ) ! continues after an exception caused by the command
- Note: irrespective of the debug setting, errors in jxn special commands always terminate
array extensions
pluggable arithmetic for primitive types
- safe arithmetic (default: automatic change of type prevents overflow and loss of precision)
- see PluggableArithmetic.html, JxnPortable/docs/
- java arithmetic (overflow handling as in java, usefull for prototyping)
- to change to java arithmetic enter:
JxnPrimitiveWrapper.setPluggable( "Java" )
- to return to safe arithmetic enter:
JxnPrimitiveWrapper.setPluggable( "Safe" )
missing java operators (relational, boolean, bitwise)
- available as static methods in class
JxnUtilities
:
- relational: eq, ne, lt, le, gt, ge, isSame, isNull
- boolean: not, and, or, exor
- bitwise: not, and, or, exor, left, right, right0
- in JXN the arithmetic operators also used for
boolean x
and y
are given in the table:
| JXN | Java |
exor | x ^ y | x ^ y |
not | -x | !x |
and | x * y | x & y |
or | x + y | x | y |
the operator preference for boolean is the same as for arithmetic operands
no L-values (→ Wikipedia: de | en)
- instead of
arr[i] = expression
use set( arr, i, expression )
- instead of
obj.fieldname = expression
use set( obj, "fieldname", expression )
( note: slider dependency is not transfered to arr
and obj
=> subsequent statements depending on arr
or obj
are not repeated,
see SliderRepeatNopDemo.html and use nop(depVar)
to force repetition of statements depending on arr
or obj
)
also see
JxnMissingFeaturesWorkaround.html
design objectives of JXN
- quick math, alternative for pocket calculator, function plotter
- slider animated demos (standalone
and embedded in html the later no more works 😞 with abandoned Java → Applets.
Java → Web Start is a more than poor substitute)
- quick development of (not too big) applications (see gallery for examples)
- data analysis (see tutorial)
- REPL for java (read-eval-print-loop)
- rapid prototyping (exploring java features)
- extensibility by user defined java classes
- not intended for large (type) safe applications (my recommendation, however some people do really big data bases with MS Excel)