Book contents
- Frontmatter
- Contents
- INTRODUCTION
- GETTING STARTED WITH JAVA
- MIGRATING TO JAVA
- HOW TO SUCCESSFULLY MIGRATE TO JAVA
- KISSIN' COUSINS: COMMUNICATING BETWEEN JAVA AND JAVASCRIPT
- TECHNIQUES 101
- MODELING AND PATTERNS
- JAVA IN A DISTRIBUTED WORLD
- THREADS
- USER INTERFACES
- SECURITY
- TESTING
- PERFORMANCE
- REALITY CHECK
- INDEX
KISSIN' COUSINS: COMMUNICATING BETWEEN JAVA AND JAVASCRIPT
Published online by Cambridge University Press: 06 July 2010
- Frontmatter
- Contents
- INTRODUCTION
- GETTING STARTED WITH JAVA
- MIGRATING TO JAVA
- HOW TO SUCCESSFULLY MIGRATE TO JAVA
- KISSIN' COUSINS: COMMUNICATING BETWEEN JAVA AND JAVASCRIPT
- TECHNIQUES 101
- MODELING AND PATTERNS
- JAVA IN A DISTRIBUTED WORLD
- THREADS
- USER INTERFACES
- SECURITY
- TESTING
- PERFORMANCE
- REALITY CHECK
- INDEX
Summary
After my last article for Java Report (“Tapping the Power of JavaScript,” March 1997), I received a question from a reader asking if there was some way for a Java applet to call a JavaScript function. I knew that JavaScript could call Java funtions, but I wasn't sure if things would work the other way around. So, it was off to the Internet to investigate! I wound up at Netscape's official JavaScript documentation site and here's what I found.…
THE BASICS
First, let's answer the question that started all this: Yes—Java methods can call JavaScript code, and JavaScript code can call Java methods. However, as you might expect, there are some exceptions and restrictions, and those depend on which browser you are using (we'll discuss these a bit later on).
The second question you might have is: “Why on earth would you want to do this?” Well, contrary to popular belief, JavaScript isn't just “Java lite,” it's a powerful and useful language in its own right. However, because it's intended to execute inside a Web browser, it does have a few things missing from it. For example, in JavaScript, you have no way to play a sound or access a database. Java has both of these capabilities, and by making them available to JavaScript, we greatly enhance the types of tasks it can perform.
- Type
- Chapter
- Information
- More Java Gems , pp. 31 - 48Publisher: Cambridge University PressPrint publication year: 2000