title: Invoke java using JavaScript inside JavaFX. Is it possible?
body: <p>I am using <code>WebEngine</code> &amp; <code>WebView</code> from <code>JavaFX</code>. Now I want to execute Java using javascript running inside <code>WebEngine</code>.</p>
  
  <p>My question is if it is possible to do so and if yes any hints.</p>
  
  <p>I want do something like below</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
    function runSampleJava() {
      var number = new java.lang.Integer(1234);
      var random = new java.util.Random();
      java.lang.System.out.println(random.nextInt());
    }
  &lt;/script&gt;
  </code></pre>
  
  <p>Now if I call the <code>runSampleJava()</code> inside <code>WebEngine</code> it will execute that code.</p>
  
  <hr>
  
  <h1>Points to be noted</h1>
  
  <ul>
  <li>This is not about <code>Rhino</code> JavaScript engine for java</li>
  <li>I know it is possible to inject java object, eg: <code>JSObject window = (JSObject) webEngine.executeScript("window");</code> and so on. But this is not what I am looking for.</li>
  </ul>