Java Tutorial/Trail: Java and Javascript

Java to JavaScript communication
The class  found in the JRE directory in the "lib/plugin.jar" archive is the object that allows communication with the JavaScript engine. The content of the JAR is automatically available inside the Java environment of the web browser. The following code instantiates the JSObject:

JSObject
offers the following methods:

JavaScript to Java communication
Calling Java methods from JavaScript is almost too easy, because the Java code exposes all public functions, not just methods intended for communication with the enclosing HTML page. If the applet or object tag has an id of "myApplet" the following code calls into the Java applet:

It is even possible to call methods unrelated to the applet itself with the  keyword:

Example: Mozilla Persona for Applets
This example applet communicates with JavaScript to permit a login to the Mozilla Persona authentication system offered by Mozilla. Discerning readers will notice that the assertion returned by the authentication system could require some sort of verification, which should, for security reasons, not be implemented in the applet. One method of verification is the Remote Verification API.