|
JavaScript is Not Java
Clearing up a common confusion
By Eric Giguere
November 8, 2004
Every once in a while, I run across someone who thinks that
Java and JavaScript are the same thing. Or that they're
closely related to each other. This is understandable
they certainly sound related. But they're not. It's
more an accident of history than anything else.
JavaScript is a Scripting Language
JavaScript is a prime example of a scripting language.
John Ousterhout, of Tcl fame, puts it this way:
|
Scripting languages are designed for "gluing" applications; they
use typeless approaches to achieve a higher level of programming
and more rapid application development than system programming
languages. |
from the abstract to Scripting: Higher Level Programming for the
21st Century |
| |
According to Ousterhoust, systems programming languages are
languages like C++ that are strongly typed and are used
to create applications "from scratch". Scripting languages, on the other
hand, are languages like Perl or Rexx that are typeless and are used
to connect existing components (usually written in another language)
together to form a new application or extend an existing application.
If you look closely at JavaScript, it definitely fits the criteria
of a scripting language: it has a simple, typeless syntax, and its
primary focus is the manipulation of HTML pages (including responding
to user-generated events). Although you can use JavaScript to
build entirely browser-based applications (this is the approach
used by AvantGo in its offline browser-based application
development toolkit,
M-Business
Anywhere note, AvantGo is now part of
iAnywhere
Solutions, my employer), most of the time JavaScript is used as the glue
that enhances HTML pages by manipulating the properties and events
of the components that make up the page.
Java is NOT a Scripting Language
On the other hand, Java is clearly not a scripting language
by this definition. When Java first came out, Sun and others
promoted its use in building applets small applications
that run within the context of a web page but that aspect
never caught on due to various issues. Java turned out to be
a great language for building server-side applications,
however applications where the logic ran entirely on a server
and there was either no user interface or a browser-based
user interface. Java also found a bit of a niche in the writing
of desktop-based applications, though there it primarily appeals
to those who need the application to run on multiple platforms.
So why are the two languages confused?
The Infamous Press Release
The problem started when Sun and Netscape issued a joint
press release on December 4, 1995 titled
Netscape
and Sun Announce JavaScript, the Open, Cross-Platform Object Scripting
Language for Enterprise Networks and the Internet. (Whew!)
You see, up to that point what we now know as JavaScript was
known as LiveScript.
According to JavaScript:
Past, Present and Future, the Netscape team initially
considered using Java as a way to make web pages "more dynamic"
but decided that Java was a better option "for buliding
components and not simple, easy-to-tweak scripts". So they
built their own language and called it LiveScript. It had some
similarities to Java, but Java itself has similarities with
C and Pascal. The nice thing about LiveScript was that it
was truly a scripting language, so you didn't need to compile
the code and you didn't need to design classes you just
started coding.
So why was LiveScript renamed to Java? It's one of those
classic marketing mistakes that are made when the gap between
the marketing people and the people who build and design the
technology is too great. True, JavaScript could be used to
control applets to some degree to it, applets were
just another component of a web page but the
integration going back the other way around was lacking.
The renaming would have made sense if JavaScript was a subset
of Java, but the fact is that learning one of the languages
doesn't give you any expertise in the other. They are truly
independent.
JavaScript is not Java. End of discussion!
|