5/15/11

The Differences between Java and JavaScript

    • Java and JavaScript are both object-oriented languages. Aside from this fact and their similar names, few parallels exist between Java and JavaScript. People who know how to use one language often become confused when they attempt to learn the other, expecting more similarities than they find due to the similar names. Java applets run as standalone programs while JavaScript scripts run in conjunction with HTML in web browsers.

    History

    • Sun Microsystems originally created Java as an object-oriented programming language. Java can create programs that work across multiple platforms. Netscape developed JavaScript as an object-oriented scripting language that's used within a web browser. JavaScript was designed to rely on other structures, such as a web browser. Java programmers create applets, or small programs that can run anywhere, while JavaScript programmers write functions that can only run on the internet. Due to a smaller command set, programmers can learn how to design JavaScript classes in less time than learning Java.

    Execution

    • A programmer must compile Java code before the program can run. A compiler turns Java code into machine language code before a browser can interpret it. Any changes the programmer makes to the code will require him to recompile the program. A web designer can write JavaScript functions directly in a text editor, save the file and upload it to the server for immediate execution. JavaScript compiles when a user visits a website. JavaScript extends a web page's interactive ability by performing tasks not capable in HTML alone. JavaScript can work with other languages such as HTML, PHP and AJAX while Java runs within a browser on its own.

    Syntax

    • Java and JavaScript differ in the syntax for creating variables and functions. In Java, a user declares a function similar to traditional programming languages such as C++ or Visual Basic. For example, a programmer can create a function by typing "public int funcName (int number)," while in JavaScript he can create the same function with "function funcName(number)" only. Java creates variables by declaring a datatype before a name, such as "integer number;" while JavaScript uses the generic "var" to declare all variables (such as "var number") and does data conversion when needed.

    Implementation

    • To run Java applets, a web browser must have Java support downloaded and installed. To run JavaScript scripts, the web browser must have enabled JavaScript functionality in the options menu. If a user allows his browser to utilize one of the two languages, the other does not automatically become activated. He must turn on both individually.

  • No comments: