Java vs. Javascript

Java

JavaScript

Java is an object-oriented programming language that was created by Sun Microsystems in 1991 for use in consumer goods like VCRs. In the mid-1990's Java became a popular programming language for the World Wide Web, and it has increased in popularity sinc e. Java's popularity for Web applications has, in large part, been a result of the popularity of Netscape. (The Netscape Navigator browser has supported Java since release 2.0. )

Recently, Java has been in the news because its developers, Sun Microsystems, have tussled with the Microsoft Corporation over Microsoft's licensing agreement with Sun. Microsoft has not included important Java development material in its developer's ki t for Internet Explorer 4.0. (Jones) At the heart of the conflict is Java's identity: is Java a language or is Java a platform? Sun says Java is a platform--the company has 3,000 Java-based network computers at their company. Microsoft has countered b y saying that Java is just a language. (Engst) Another sticking point is Microsoft's reluctance to support the "100% Pure Java" endeavor by Sun. Java's official slogan "Write once, run anywhere" is indictative of the language's portabilty. It is a lang uage than can used for any programming application, not just Web programming, and it can be used on any computing platform. Microsoft, a company that has sold the most Java development tools, offers development tools that allow programmers to write Wind ows-specific Java, and that impinges upon the portability of Java. And there's the rub. And the lawsuit. (Wired)

Most of the time, when a computer program is translated into machine code ("compiled") so a computer can understand it, the resulting machine code can only be understood by other computers of the same system type. Java, however, is different. When a Jav a program is compiled, it can be run on various platforms (it is "portable"). This portability, and the fact that Java applets are small and speedy, make Java an ideal programming language for the Web. The Web itself is platform independent. (Javasc ript takes this further--a Javascript applet does not need to be compiled. This is one of the biggest differences between Java and Javascript.)

Java is easier to learn than C++, the language it was modeled upon. For experienced programmers, it is quite simple. Novice Java programmers, on the other hand, first have to understand the basics of object oriented programming.

Small Java programs ("applets") can be inserted into HTML documents using the SGML-compliant <APPLET> tag. Java enables static HTML documents to become interactive, by adding features like forms, by manipulating user input, and by helping to automate Web design and maintainance.

Java 1.0 is supported by: Netscape Navigator for Windows 2.0 and above; Netscape Navigator for Macs 3.0 and above; Internet Explorer 3.0 and above; and Sun's HotJava.

Only one browser fully supports Java 1.1: Sun's HotJava. Netscape's Navigator Communicator and and Microsoft's Internet Explorer 4.0 only support portions of Java 1.1. (Harold)

References:

DevEdge Champion
Netscape DevEdge Newsgroup Frequently Asked Questions: Java

Engst, Adam C.
Reading the Coffee Grounds
In MacWeek Online December 3, 1997

Harold, Elliotte Rusty
comp.lang.java FAQ

Wired
The Truth About Java: What is it anyway?
In Wired News December 8-11, 1997.

Javascript began as an attempt by Netscape Communications to integrate the functionality of Sun Microsystems' Java programming language with HTML for WWW applications. The hope was that this new language, which would be a "scripting language," would be simpler to understand than Java and would provide web designers with the ability to include interactive elements in their pages without having to master a complex programming language. The initial attempt yielded a scripting language known as "LiveScript." Recognizing the value of this project, Sun joined forces with Netscape, and "LiveScript" became "JavaScript."

HTML is the markup language used for Web-based documents. It allows a designer to create a static environment for her content. If the designer wants to include dynamic elements in her page, she must turn to a scripting language such as JavaScript, an i nterface like CGI that utilizes a scripting language such as Perl, or a programming language such as Java or C, to accomplish this. CGI is the most commonly used interface that allows scripting on the Web, and designers use it to include interactive elements such as forms and search engines in their Web pages. However, CGI is "server-side." This means that the program runs on the server that it resides on, rather than on the user's machine (client side). If a connection is slow, or the server is overtaxed or otherwise limited, a server-side application may be relatively slow, and may take a long time to run. JavaScript is a "c lient-side" process, similar to Java. It loads and runs on the user's machine, and does not require calls back and forth to the server for its implementation. This gives it the potential to produce faster results than a server-side application.

A scripting language is a language that consists of "a sequence of program instructions (called statements)." (Idiot, 12) This is programming, but scripts are simpler to learn and set up than programming languages. JavaScript, like Java, is object-oriented. This simply means that when a person is writing a JavaScript, she is concentrating on the various pieces, or objects, that she needs to work with in her program.

A web page consists of many different objects that can be affected with a JavaScript. There can even be objects within objects. For instance, the HTML document that generates the web page is an object, and each sub-section of that document can also be an object: a text box, a radio button, a form. The browser window itself is an object, as is the status bar of the browser, etc. "The basis for the concept of object-oriented programming [is that] the programmer is more concerned with what an object is doing than how it gets done." (Idiot, 13) However, JavaScript has objects built-in that provide the designer/programmer with the functionality she needs. New objects can't be created, like they can in Java, so the designer/programmer doesn't have to worry about originali ty.

The main problem with JavaScript, currently, is its portability. It can only be fully implemented on Netscape's browser, and only version 3 or greater. It tends to crash earlier versions of this browser. Microsoft's Internet Explorer implements ActiveX, a competitive technology, but does not recognize JavaScript. To avoid browser conflict, designers should create a site that will allow users with different browsers to access different pages according to their browser's ability to view JavaScript. Netscape's online magazine, "View Source" (http://developer.netscape.com/news/viewso urce/), offers advice on setting up a mechanism on a web page that will detect a user's browser and route that user to an appropriate page (see Detecting a JavaScript Client by Danny Goodman). Designers should also include <ALT=""> tags in their HTML code whenever JavaScript is called to provide an alternative to the JavaScript function.

JavaScript is easily integrated into the HTML code for a web page. The script resides in the header information, and is "commented" off so non-JavaScript browsers cannot view (or recognize) the code. Function calls that refer back to the script are plac ed within the main HTML code of the web page. Unlike Java or CGI, JavaScript does not require a separate file for code, although the designer has the option of placing her code in a separate file. Again, JavaScript is an attempt to put the capability for creating interactive, dynamic web pages into the ha nds of the non-programmer.

References:

Brumbaugh, Heidi. "Introduction to JavaScript: A Tutorial on Netscape's Scripting Language Extension to HTML." _Web Developer_ (May/June 1997): 46-53.

Goodman, Danny. Detecting a JavaScript Client. In View Source.

Ready, Kevin, Paul Vachier and Benoit Marsot. _Plug-n-Play Java Script_ Indianapolis, IN: New Riders Press, 1996.

Walter, Scott J. and Aaron Weiss. _The Complete Idiot's Guide to JavaScript_ Indianapolis, IN: Que, 1996.


Major Differences

Java JavaScript


  • Can be used for various programming purposes.
  • Is a compiled language.
  • Code is compiled into Applets (separate from HTML).
  • Is a programming language.


  • Is used for Web programming only.
  • Is not a compiled language.
  • Code is embedded directly in HTML.
  • Is a scripting language.


Back to Main Java vs. JavaScript Page
Applets vs. Scripts | Comparison Chart | Resources