Thursday, 7 December 2017

Comparing JavaScript with Other languages

Java is actually a very small language when compared with other object-oriented programming languages such as C++. Nevertheless, it has a large number of capabilities.
The extensive set of built-in functions and objects known as the Java class hierarchy, for example, implements an extremely rich and powerful set of tools for image manipulation and network access, among other things.

Java variables must be explicitly declared with a particular data type. Java is very similar to the C and C++ programming languages in terms of the types it supports.
Java, however, rigidly specifies the size and representation of its various types so that there can be no confusion. If you have ever tried to port a C program from a DOS or Windows environment with 16-bit integers to a UNIX or Windows-NT environment with 32-bit integers, you know from firsthand experience how frustrating such low-level problems can be.

There are several differences between the object models of Java and JavaScript, as well as their terminologies.Java refers to its objects as classes, unlike JavaScript.
Java object members are referred to as instance variables, rather than properties. Instances and methods have the same meaning in both languages.

Java has no independent functions, only methods. These differences arise from the fact that Java is both explicitly typed and strongly typed. In Java every piece of data must have a type. Every structured data type, such as String, is a class, while the data itself is an instance of that class.
This concept of strong typing pervades all of Java, and is even reflected in the differences in terminology with JavaScript.

In JavaScript the focus is on responding to events. A user action produces an event that triggers a JavaScript event handler, which does something useful.
In Java, user events are handled very differently. When the user loads a Web page containing Java code, in the form of a Java applet, the browser tells the applet to start. When the user leaves that page the applet is told to stop.

While JavaScript code is ultimately event driven, and intimately tied to its HTML environment, Java applets are much more independent. An applet may respond to a mouse click within its active area, but it won't be listening for the sound of a Submit button being pressed.
An applet is a little application that lives in its own world, for the most part. JavaScript code is more like a Dynamically Loaded Library which is activated in response to something.

JavaScript takes a very relaxed attitude towards variables and functions. Variables are typeless, and the distinction between functions, objects, and arrays is blurry at best. By contrast, Java is an extremely strict language.
All Java variables have an explicit data type. Types may only be converted to one another under very well defined conditions, and only by using explicit type conversion functions. Java also enforces static name binding, instead of JavaScript's dynamic binding. Referencing an undefined function is impossible.

Sometimes it's desirable to initially leave a frame blank and load the contents later. For instance, the value of the frame may depend on user input or the result of a lengthy calculation or process.
You could load an empty document from the server, but that wastes a server access. It's faster and easier to use the javascript: protocol to load the empty document internally.
JavaScript can be used to create several useful visual effects, including alternating color schemes, fades, scrolling marquees, and dynamic graphics.
Unlike effects created using other tools, JavaScript effects load quickly as part of your document, and can start even before a page is completely loaded.

You've often seen http: or ftp: at the beginning of a URL. This is the protocol: it tells the browser which protocol handler to use to retrieve the object referred to after the colon. The javascript: protocol is really no different; it simply instructs the browser to let JavaScript retrieve the object.
But rather than initiate communication with another server, the JavaScript handler returns the value of the variable or function cited after the colon. The value returned should be HTML or some other MIME type the browser knows how to display.