Invoke Java code from Javascript

Standard Java Classes To use the standard Java classes from Javascript, there are only 2 steps:

  1. Insert Packages in front of the fully qualified name of the Java class that you would like to use.
  2. Assign that fully qualified class name to a local variable.

Here is simple example illustrating the 2 steps:

var myJsVariable = new;    

Another more complex example:

// Javascipt
var ArrayList =;
var jArray = new ArrayList(); // Creating ArrayList object.
jArray.add(1); // Using add() of ArrayList object.
// Using Java's static System.out.println() method.
var jOut =;
for(var i = 0; i<jArray.size(); i++)

If the code above is executed, then the output will be displayed in the Java Console of your Firefox located at Tools->Java Console.