Java and Javascript Compare and Contrast
By: Tommy • Essay • 2,433 Words • November 17, 2009 • 1,053 Views
Essay title: Java and Javascript Compare and Contrast
Abstract
The following research paper is written with the intent to give the reader information on the differences between JavaScript, Java and Java Applet and the usage of multi-media for web sites.
Research Results
Java and JavaScript Compare and Contrast
JavaScript at first glance looks like Java. The major difference is that JavaScript does not have Java's static typing and strong type checking. The basic control flow and syntax of Java are supported by JavaScript. JavaScript supports a run-time system based on a small number of data types representing numeric, Boolean, and string values, unlike Java's compile-time system of classes built by declarations. JavaScript supports functions so those 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 byte codes.
Java programs consist of classes and their methods and 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. JavaScript on the other hand, descends in spirit from a line of smaller, dynamically typed languages like HyperTalk and dBASE. The other languages offer programming tools for a much wider audience because of easier syntax, specialized built-in functionality, and minimal requirements for object creation.
The following table compares and contrasts JavaScript and Java (Java Script Resources 1999).
JavaScript Java
Interpreted (not compiled) by client. Compiled on server before execution on client.
Object-based. Code uses built-in, extensible objects, but no classes or inheritance. Object-oriented. Applets consist of object classes with inheritance.
Code integrated with, and embedded in, HTML. Applets distinct from HTML (accessed from HTML pages).
Variable data types not declared (loose typing). Variable data types must be declared (strong typing).
Dynamic binding. Object references checked at run-time. Static binding. Object references must exist at compile-time.
Cannot automatically write to hard disk. Cannot automatically write to hard disk.
Uses of Java and JavaScript
As stated above, Java can be a stand-alone program compiled and executed directly on the users’ computer. JavaScript is used in web pages and is embedded into the direct HTML coding of a particular page. This difference may seem insignificant but in reality is very noteworthy. The main uses of Java and JavaScript may seem similar in many fashions but the implementations, and complexity, play a major role in the decision to use one over the other.
When designing a web page, Java applets can be called and executed but this method is not ideal. With the use of Java needing compilation on the client’s machine, this procedure is inefficient in the majority of web applications. Conversely, the use of JavaScript requires no compilation on the client machine and is more efficient. JavaScript is much less complex than Java and can be more easily used in fluid applications that are used on the web pages today. While JavaScript is simpler in design and more efficient for web page creation, JavaScript has limitations to consider.
Java is a much more complex language that requires more coding accuracy and technical experience in the language. With this added complexity comes much more robust capability. Java can be used to create much more complex and powerful applications that are not possible using JavaScript. While they both can be used to create very nice web features and tools, Java can be used to create powerful and robust stand-alone applications such as databases, browsers, and fully-functioning programs (Burns, 2007). The complexity of the language doesn’t necessarily create this added capability for Java, instead the added complexity and structure make the language more capable of performing complex operations across systems and provide the desired results.
The