Best view in Firefox and Chrome

JavaScript to Java Communication

Friday, January 9, 2009
Convert Article to PDFPrint ArticleEmail Article to FrinedBookmark this Article

For my final year project I worked on firefox extension (eID Browser extension ) and a Java Desktop application (eID Desktop Application ). Normally all the dynamic scripting in firefox extension is developed on JavaScript. And the all the codes in eID Desktop Application is in Java. So I needed some communication mechanism in between the the eID Desktop Application and the eID Browser extension. From the googling I found that I can use the special LiveConnect objects to communication. Here I like to give some my experiences in JavaScript to Java Communication and Java to JavaScript Communication. When you refer to a Java package or class, or work with a Java object or array, you use one of the special LiveConnect objects. All JavaScript access to Java takes place with these objects, which are summarized in the following table. Please refer this table.

JavaArray A wrapped Java array, accessed from within JavaScript code.
JavaClass A JavaScript reference to a Java class.
JavaObject A wrapped Java object, accessed from within JavaScript code.
JavaPackage A JavaScript reference to a Java package.
Table for The LiveConnect Objects

Then another important point is Java is a strongly typed language and JavaScript is weakly typed, the JavaScript runtime engine converts argument values into the appropriate data types for the other language when you use LiveConnect. The existence of the LiveConnect objects is transparent, because you interact with Java in a fairly intuitive way. For example, you can create a Java String object and assign it to the JavaScript variable myName by using the new operator with the Java constructor, as follows: var myName = new java.lang.String("My name is Subanu"); In the above example, the variable myName is a JavaObject because it holds an instance of the Java object String. As a JavaObject, myName has access to the public instance methods of java.lang.String and its superclass, java.lang.Object. These Java methods are available in JavaScript as methods of the JavaObject. In my next post I'll tell about the The Packages Object in LiveConnect. Click here to read that post.

Read these Articles :


Anonymous said...

Hello. And Bye.

Why Breeze

This is a new technological rhythm in the web. It blooms like a Breeze in your technological face with more than 75 technoligical atricles and guidences.

Contact Me
Contact Me Send an Email Facebook Account LinkedIn profile Twitter/Shayanth
Share And Save
Social Share with Twitter Facebook Share Add to Google Save on Delicious
Get Updates

The RSS will facilitate you to get the updates from Breeze. Click Here to redirect to the RSS link.

Designed by Posicionamiento Web | Bloggerized by GosuBlogger | Blue Business Blogger | Customized by SHAUOM