JavaScript to Java Communication
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.
Object | Description |
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. |
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.
This Articles was posted on 7:37 PMFriday, January 9, 2009
|
Labels:
Experiences,
Firefox,
Java,
JavaScript,
Project work,
Tech
|
1 comments:
Hello. And Bye.
Post a Comment