Java and JavaScript: Not the Same

0
8

A common problem for programmers is confusing the two programming languages ​​Java and JavaScript. While the two languages ​​share some similarities, they are very different beasts and generally used in different applications.

Java is a general-purpose programming language developed by Sun Microsystems as a way to let programmers "write-once, run anywhere". Java code is executed inside a virtual machine, so a Java application can be distributed without the developer having to worry about the different architectures and operating systems that the application might run on.

JavaScript, on the other hand, is a scripting language. It's only purpose is inside of web pages. When a web browser loads the page, it executes the JavaScript code inside it. The code can change how the web page looks and operates. For example, JavaScript code can be used to create a drop down menu that expands when you mouse over it, or an image gallery where the displayed image changes every so often.

This difference is most evident in the libraries of the two languages. Java has a large standard library that's been standardized in the Java standard. This allows Java programmers to use a wide variety of tools when writing code. JavaScript's standard library is much smaller and generally related to working with the HTML code in the web page.

Further confusing the two languages ​​is the fact that Java can also be used in a web page in the form of a Java applet. This is a small part of the web page where Java code runs and is displayed in the browser window. Java applets are generally used to create more advanced things in the browser, a game for example. JavaScript is not nearly powerful enough to create a complex game, so Java is used. This is where Java's platform-independent advantage comes in. As long as the web browser has the Java plugin (and most do), the code will run the same no matter which web browser is used. This can not be said for JavaScript, which is often implemented differently in the different web browsers, requiring various compatibility hacks.

And since the fact that both can be used as web languages, JavaScript is vastly more important for the aspiring web programmer to learn. JavaScript's simplicity also means that it runs quickly, so that small things you may want to add to a web page are not bogged down by Java's virtual machine. This is a reason why Java is not used much on the web anymore: because it's slow. A Java applet requires the loading of the large Java plugin and is overkill for all but large web projects, especially when more flexible tools such as HTML5 are becoming more widely used on the web.

Java and JavaScript are two different programming languages. Each of them have their uses, but they are not interchangeable with each other.

Source

Leave a Reply