many people use the words java and javascript interchangeably, or confuse the two. the javascript language resembles java, but without java's static typing and strong type checking. javascript supports most of java's expression syntax and basic control flow constructs. in contrast to java's compile-time system of classes built by declarations, javascript supports a run-time system based on a small number of data types representing numeric, boolean, and string values. javascript has a simple instance-based object model that still provides significant capabilities.
javascript also supports functions, again without any special declarative requirements. functions can be properties of objects, executing as loosely typed methods.
javascript complements java by exposing useful properties of java applets to script authors. javascript statements can get and set exposed properties to query the state or alter the performance of an applet or plug-in.
java is an extension language designed, in particular, for fast execution and type safety. type safety is reflected by being unable to cast a java int into an object reference or to get at private memory by corrupting java bytecodes.
java programs consist exclusively of classes and their methods. java's requirements for declaring classes, writing methods, and ensuring type safety make programming more complex than javascript authoring. java's inheritance and strong typing also tend to require tightly coupled object hierarchies.
in contrast, javascript descends in spirit from a line of smaller, dynamically typed languages like hypertalk and dbase. these scripting languages offer programming tools to a much wider audience because of their easier syntax, specialized built-in functionality, and minimal requirements for object creation.
the following table compares and contrasts javascript and java.
JavaScript
-Interpreted (not compiled) by client
-Object-based. Code uses built-in, extensible objects, but no classes or inheritance
-Code integrated with, and embedded in, HTML
-Variable data types not declared (loose typing).
-Dynamic binding. Object references checked at run-time.
-Cannot automatically write to hard disk.
Java
-Compiled on server before execution on client.
-Object-oriented. Applets consist of object classes with inheritance
-Applets distinct from HTML (accessed from HTML pages).
-Variable data types must be declared (strong typing).
-Static binding. Object references must exist at compile-time.
-Cannot automatically write to hard disk.
Friday, May 23, 2008
the differences between java and javascript
Labels:
web design/programming
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment