|
By Mark Wilcox, Campus Web AdministratorJavaScript and Java: "Kissing Cousins"I thought that in this month's www@unt.edu, I would try to remove some of the confusion surrounding the JavaScript and Java programming languages. First let's get something straight, JavaScript is not Java and Java is not JavaScript. They are two entirely different languages. JavaScript*JavaScript was originally created by Netscape as an object-oriented scripting language that could be used to give Web developers more control over their Web pages. With JavaScript it is possible to validate form information before sending it to the server. You can put a scrolling marquee on your Web page or you can do image rollovers, like we do on the UNT homepage. If you are a really cutting edge Web developer, you can use JavaScript to add many different effects using Dynamic HTML. JavaScript, however, has now moved beyond the browser into a standard object-oriented scripting language. It has become standardized through the European Computer Manufacturers Association (ECMA). The standardized version of the language is called ECMA-Script. Microsoft has implemented their own version called Jscript (though it mostly conforms with Netscape's version, so scripts for Communicator usually run in Internet Explorer). In Windows 2000 you will even be able to automate Windows tasks with JavaScript using the Windows Scripting Host. As part of the Mozilla opensource project, Netscape has released the source code for the JavaScript engine. This means that if you are building an application and want to add a scripting tool to allow your users the ability to automate tasks inside your application, you can now use JavaScript as that scripting tool. When you do this, your users will be able to automate this application using a language they are already likely to be familiar with. There are already examples of where companies have done this with success. Macromedia Dreamweaver is a Web development tool for very advanced users, specifically for creating dynamic Web sites. When you create dynamic sites, you must make heavy use of JavaScript. If you were to code this by hand, you would either lose your mind or get a good case of carpal tunnel syndrome. Dreamweaver allows you to do this with drag and drop (though you can code by hand, Dreamweaver in many ways shows you how you should write a visual development tool), with "behaviors". You can add your own behaviors and automate repetitive tasks in Dreamweaver by using JavaScript. Adobe will be adding support for JavaScript for their update to the popular Adobe Acrobat reader. With JavaScript and Acrobat you will be able to actually fill out a form in the PDF file (PDF is Adobe's file format) and submit that form to a Web server. JavaThe Java programming language was developed by Sun Microsystems, originally as a language for developing applications for hand-held devices and "set-top" boxes like WebTV. When the Web appeared, Sun transformed the language into a development tool for adding more sophisticated environment to your Web sites without plugins. Java's key phrase is "Write Once, Run Anywhere". What this means is that Java is platform independent. You can compile (e.g. turn the program into executable code) on one machine and run it on any other machine, regardless of its operating system, as long as the operating system has a Java Virtual Machine. There are three types of Java programs. One is an applet and is designed to run only inside of a Web browser. The second type of program is a servlet which is a program designed only to run in conjunction with a Web server. The third type is an application which can run outside of a browser or a server, just like a traditional application like Microsoft Word. Unfortunately the original Java that appeared in Web browsers didn't work very well (in particular the graphical user interface elements) and the security restrictions the browser placed on the applets, really hampered what they could do. Plus many people believed Java was too slow. Java has really made strides past this early version, but browser support still lags behind. Java on the server, in the form of Java servlets and Java server applications have really gained momentum. With the recent release of Java 2, I think Java applications will see a boom because you can now write a very good looking GUI and with 400 MHZ PCs becoming common, speed is not an issue. They Meet, They Kiss ...Now that we know they are separate languages, they do have some similarities. JavaScript's syntax is highly derivative of Java's which means they do look about the same in terms of the code you type. However, JavaScript is a weakly typed language, and Java is strongly typed. What this means is that a JavaScript variable can store a number, a string or a JavaScript object, in the same script! In Java, a variable is required to be of only one type (e.g. a number, a string or any other valid Java object). Both Netscape and IE "LiveConnect," which gives the ability for JavaScript to communicate with Java applets. In Netscape your Java applets can also communicate with JavaScript (IE 4 supports this too, but it's not documented so use at your own risk). In another twist, someone has written a JavaScript interpreter that runs inside of Java, so if you write a Java application, you can make JavaScript your scripting language! Until next time. Mark * If you are interested in JavaScript you might want to subscribe to the newsletter highlighted in this month's List of the Month. Resources:Netscape
JavaScript Central |