Java method calls (Definition)

JavaScript allows Java methods to be called natively.

Access to the methods of Java objects is very simple. They appear to be native JavaScript methods. To all intents and purposes, they are no different to the other built-in objects such as Math, Boolean, String, Date etc.

There is a subtle difference between the two environments in that JavaScript methods are forgiving about the number and type of arguments whereas Java is not. There is also some ambiguity regarding data types when calling Java methods. It is possible to overload a method in Java and provide alternative interfaces to support different data types. JavaScript can only cope with calling the first interface it encounters and cannot select an appropriate one based on the data type of the method arguments.

You may be able to limit the problems here by carefully considering the data types and coercing them in the script.


See also:LiveConnect


Wrox Professional JavaScript - page - 537