Log in

No account? Create an account
Ramblings Journals I Read Calendar The Dirt MegaZone's Waste of Time Older Older Newer Newer
KBlogger: Pet Peeve - JavaScript is NOT Java! - MegaZone's Safety Valve
The Ramblings of a Damaged Mind
KBlogger: Pet Peeve - JavaScript is NOT Java!

OK, I'm working on the next entry in my one man rally for standards support, but I saw something today that reminded me of a pet peeve I've had for many years. An author make the classic mistake of mixing up Java and JavaScript. This happens all the time, and it is really frustrating. First of all, because it is simply incorrect. Second of all, because it confuses newbies and experienced developers alike to have someone talk about using 'Java in the browser', when they don't mean Java Applets, they mean JavaScript. And, third and worst of all, it makes newbies thing Java == JavaScript, and that to do JavaScript they'll need to learn all of the ins and outs of Java, so they are daunted and avoid scripting entirely. And that's a crying shame.

Java is a full-featured, object oriented, platform independent programming language developed by Sun. JavaScript is an object scripting language developed by Netscape. The two have nothing to do with each other - really. It is an unfortunate naming choice made by Netscape to cash in on Java hype when it was new. I don't want to single anyone out, since this is something I've seen many authors fall into over the years. So lifting one line from an article I saw a few months back: "Unlike complex stand-alone Java programming applications, Java scripts and applets run within any Java compatible browser." That statement tangles up two different things. 'Java Compatible' has nothing to do with a browser running JavaScript or not. In fact, no browser natively supports Java - they all need a Java Virtual Machine (JVM) to be installed on the system, and they allow the JVM to run Java. But JavaScript is natively supported within the browser, completely independent of any Java compatibility. You want a JavaScript compatible browser, which covers pretty much any modern browser.

The JavaScript page at Mozilla.org summarizes it nicely, so I'll steal a couple of paragraphs from them:

JavaScript is the Netscape-developed object scripting language used in millions of web pages and server applications worldwide. Netscape's JavaScript is a superset of the ECMA-262 Edition 3 (ECMAScript) standard scripting language, with only mild differences from the published standard.
Contrary to popular misconception, JavaScript is not "Interpretive Java". In a nutshell, JavaScript is a dynamic scripting language supporting prototype based object construction. The basic syntax is intentionally similar to both Java and C++ to reduce the number of new concepts required to learn the language. Language constructs, such as if statements, for and while loops, and switch and try ... catch blocks function the same as in these languages (or nearly so.)

Mozilla.org has another good explanation of why they are not the same. JavaScript is a scripting language - and it was originally called LiveScript. At the time everything Netscape did was Live-something; their back-end server was LiveWire, the ability to script actions on plug-ins was LiveConnect, etc - and the scripting language was LiveScript.

About the time Sun was hyping Java, Netscape was getting ready to launch LiveScript. They decided to jump in the Java hype bandwagon (I went to JavaOne the first year at the Moscone Center in San Francisco - talk about HYPE! Java was going to take over the world in a month, tops, if you believed Sun. No more C, no more C++, no nothing - Java everywhere, all the time!) - so they changed some of the language's syntax to be more Java-like, added some ability to LiveConnect to be able to have scripts communicate with Java Applets within Netscape, and, with the support of Sun, they renamed it JavaScript.

But the two languages are 100% independent. What most people call JavaScript isn't even rightfully JavaScript anymore - the language was turned over to the ECMA standards body and in its standardized form it is known as ECMAScript. There are actually a few standards that apply to ECMAScript ECMA-262, ECMA-290, ECMA-327, and ECMA-357.

The relationship between JavaScript and ECMAScript is explained well in Mozilla.org's developer documents. JavaScript is basically the 'brand name' for the Netscape/Mozilla implementation of ECMAScript, and JScript is the name of the MSIE implementation of ECMAScript. JavaScript 1.5 is an implementation of the ECMA standard, actually a slight superset of the standard with a few added features. Everyone just calls it JavaScript because it is the name in common usage. ECMA controls the language specification of ECMAScript, Sun controls the specification of Java - and with the evolution of the two languages, they have less in common now than they did at first.

There have been 6 major revisions to JavaScript, starting with the 1.0 release in Netscape 2.0 and going up to today's 1.5 standard supported in NS6.0+, Mozilla, Firefox, and others. Each generation of the language has introduced more features and more power. Most of today's browsers support ECMAScript-262 Rev.3, which roughly corresponds to JavaScript 1.5. There is a fantastic language reference available on the alpha test site for the new Mozilla developer's pages. The JavaScript reference area is full of useful information for any webmaster looking to use JavaScript on their sites.

A final, minor, peeve. The language is JavaScript. It is not Java Script, or java script, or even javascript. Yes, JavaScript, with the inter-capped 'S' and all. Don't blame me, blame Netscape, they named it. Sun's language is Java, Netscape's is JavaScript. They are two distinct languages with unfortunately similar names. I don't blame a newbie for thinking that JavaScript is some form of Java used for scripting, in fact, I'd bet that's just what Netscape's marketing people wanted everyone to think when the Java hype was it its peak. But if you're writing about the technology, please, don't perpetuate this mistake.

Tossing in something completely unrelated - check out Audioscrobbler. You can install a plug-in for your favorite audio player, like iTunes, and it will upload your listening habits and build a history. So you can look at graphs of which artists and songs you listen to, find others with similar interests, etc. Really quite exhibitionistic and voyeuristic. I've been using it since earlier this year. So now you can poke fun at my musical tastes.

Feedback is welcome. :-)

Tags: , , ,
I am: tired tired
Current Media: The Police: Message In A Box: The Complete Recordings (Disc

fallenpegasus From: fallenpegasus Date: June 7th, 2005 03:30 am (UTC) (Direct Link)
Have you seen my "I hate JavaScript" rant? I go off on a tear about the name.


Some of the responses were mildly amusing.
zonereyrie From: zonereyrie Date: June 7th, 2005 04:52 am (UTC) (Direct Link)
I actually think JavaScript 1.5 (the current) is fairly decent - with regexps, etc. But it is terribly abused.