JavaScript/Not Java

From Wikibooks, open books for an open world
< JavaScript
Jump to navigation Jump to search
Previous: Introduction Index  

Despite the similar names, Java and JavaScript, there is almost no relation aside from syntax between the two languages. Since both are frequently used on the Internet, the two can be confused by the uninitiated. In fact they were developed by two totally different companies, with differing goals and purposes in mind: Netscape developed JavaScript and Sun Microsystems developed Java. JavaScript can be interpreted by most browsers directly and quickly, while Java requires a separate "Java Virtual Machine" to be started before running. JavaScript and Java use a similar syntax (based on the C language) but many of the commands are quite different. There are also technical differences. Java is a statically typed language which requires the declaration of all variables and their types (e.g. integer, string or boolean). In contrast, Javascript is an "loosely" typed language, allowing variables to be used without prior declaration.

For example, compare the two methods of writing to the display (page). In Java, to write "Hello world!", the code would read: System.out.println("Hello world!"); while in JavaScript (in a browser), it would say: document.write("Hello world!");.

Previous: Introduction Index