Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Gluing Application Components with JavaScript

Gluing Application Components with JavaScript

My talk at JSFoo 2012 - Bangalore.
Full talk proposal at http://funnel.hasgeek.com/jsfoo/434-glueing-application-components-with-javascript

Sankha Narayan Guria

October 20, 2012
Tweet

More Decks by Sankha Narayan Guria

Other Decks in Programming

Transcript

  1. Glue? Its sticky and dirty. But holds stuff together. But

    JavaScript Glue is nice and simple.
  2. JavaScript Awesomeness • Simple, easy to learn and code with

    • Object Oriented & Functional • Dynamic data types • etc. (I can’t have enough of its awesomeness)
  3. The Bottlenecks JavaScript was originally slow Lack of useful APIs

    Existing applications are already in other languages
  4. Lets get started with the Script Engine in Java. import

    javax.script.*; class RunScript{ public static void main(String args[]) throws Exception{ ScriptEngineManager factory = new ScriptEngineManager(); ScriptEngine engine = factory.getEngineByName("JavaScript"); engine.eval(new java.io.FileReader("script.js")); } }
  5. Now we can write whatever JavaScript we want in script.js!

    value = 5; println(value + 2); value = "Hello World"; println(value);
  6. Even fancy Swing UIs also work! importPackage(javax.swing); importPackage(java.awt); var frame

    = new javax.swing.JFrame("Hello"); var button = new javax.swing.JButton("I'm a button!"); frame.setSize(500,200); frame.setLayout(new java.awt.FlowLayout()); frame.add(button); frame.setVisible(true);
  7. Just Notice! • You don’t really need to bother about

    data types. A simple ‘var’ does the job! • You can even recycle variables.
  8. Just Notice! • Use a plug-in architecture. Code the core

    application with the APIs in Java. • Let other developers build the UI, business logic rules, etc. • Add them to the application on the fly by dynamically loading the scripts.
  9. Just Notice! • Shipping updates are also easy. • Just

    deploy the scripts and they are loaded on the fly by you application!
  10. Time to fire up an example Panther - A Java

    based Audio/Video file converter. https://github.com/sankha93/Panther
  11. Create simple bindings in JS for your core functions Call

    these functions and objects from JS!
  12. Hiccups! • JavaScript tends to be slow due to old

    Rhino engine! • Project Nashorn from Oracle coming soon to deliver fast JS to the JVM.
  13. The Bottomline Binding application components Design API for your core

    functionality Modular and updatable components Scriptablity in your applications JS Glue