On the relationship between Java and JavaScript, I have seen in a forum such a sentence, Java and JavaScript relationship, like Lei Feng and Leifeng Tower relationship, is really classic!
Because of the relationship between names, there are always people who mistakenly assume that JavaScript is a subset of Java, or that there are certain relationships. But it's disappointing, but the two programming languages have no intrinsic relationship except the first name!
what is JavaScript?
In my last JavaScript introduction, I've covered what JavaScript is, which is a scripting language that runs in a browser, and in a Web page, JavaScript is omnipotent:
- The ability to manipulate HTML provides a tool for changing HTML at run time
- Events can be attached and executed in accordance with the idea of event-oriented programming
- Data validation function to validate form data when submitting a form
- Action on the client's browser, forward, rewind, refresh, jump, open new window, print, etc.
- Cookies can be created and used
What is Java?
Java is a programming language introduced by Sun. It is a language that is interpreted in a way that is similar to C + + in syntax rules. At the same time, Java is also a cross-platform programming language. In the Java language program is called "Applet" (small application), with the compiler to compile it into a class file, it exists in the WWW page, and in the HTML file to make a corresponding mark, the user as long as the Java client software can be directly run "applet" online.
Java is ideal for enterprise networks and Internet environments, and is now one of the most popular and influential programming languages on the Internet. Java has many commendable advantages, such as simplicity, object-oriented, distributed, explanatory, reliable, secure, structural neutrality, portability, high performance, multi-threading, dynamic, etc. Java rejects all the advantages and disadvantages of C + + and many features that are seldom used. Jave can be run with any microprocessor, a program developed in Java can be transmitted over the network and run on any client.
The origin of JavaScript names
JavaScript was originally called Mocha (Magic Card), which is the code name for this project. This name has been used until Netscape2.0 Beta 2 was released (95.11.04)-including the error box that was popped in Beta 1, and Mocha's name was also visible. However, as early as September 18, Netscape has published a message that will enable a server-side script in Livewire (name not mentioned). And because of the design of the "front-end Generic Script" We mentioned earlier, the language used the internal name LiveScript when it was released in Beta 2.
But the same messy thing is that, in fact, Netscape has decided to name the language "JavaScript". So in the Beta 2 release memo The language is called JavaScript, and the interface is changed from Mocha to LiveScript. The situation continued until December 4, when Netscape and Sun issued a statement that formally enabled the name JavaScript. Then the beta 4 release (95.12.20), the interface and documentation are unified.
So the fact that the name "LiveScript" can be verified in the life cycle, is only one months (in 95.11.04-12.04). But after all, Mocha is only the project code name, not the product name of the Connaught Asia Platform website , so later people trace the history of JavaScript, mostly only mentioned livescript so far.
the difference between JavaScript and Java
First, JavaScript and Java are different products developed by different companies. JavaScript is a product of the Netscape company, which is designed to extend the Netscape Navigator functionality and to develop an object-and event-driven interpretive language that can be embedded in Web pages, while Java is the sun Microsystems's new generation of object-oriented programming languages, especially for Internet application development. In fact, the original JavaScript name is not JavaScript, but LiveScript, the name "Java" is authorized by Sun Microsystems Company.
Second, JavaScript is Object-based, it is a scripting language, is an object-based and event-driven programming language, so it itself provides a very rich internal objects for designers to use. And Java is object-oriented, that is, Java is a true object-oriented language, even if the development of a simple program must design objects.
Third, JavaScript and Java embedding method is different. In an HTML document, the identities of the two programming languages are different, JavaScript is identified using <script></script>, and Java is identified using applets.
JavaScript does not perform the same way as Java does in the browser. JavaScript is an explanatory programming language whose source code is not compiled until it is sent to the client, but instead sends the character code in the text format to the customer, which is the JavaScript statement itself that is downloaded with the Web page and interpreted by the browser. Java's source code must be compiled before it is passed to the client, so the client must have an emulator or interpreter on the appropriate platform, which can be compiled from a compiler or interpreter independently of a particular platform.
V. JavaScript is not the same as Java code format. JavaScript code is a form of the address, can be directly embedded in the HTML document, and can be loaded dynamically, writing an HTML document is as easy as editing a text file, its independent file format is *.js. Java is an HTML-independent format that must be loaded by referencing an external media like HTML, whose code is stored in a separate document in the form of a byte code, with a separate file format of *.class.
Vi. the variables that JavaScript and Java take are different. Variable declarations in JavaScript are weakly typed, meaning that the variables are not declared before they are used, but rather that the interpreter checks their data types at run time. Java uses strongly typed variables to check that all variables must be declared before they are compiled.
Vii. JavaScript uses dynamic linking, which is a JavaScript object reference that is checked at run time. Java uses static linking, meaning that Java object references must be made at compile time, so that the compiler can implement strong type checking.
JavaScript does not directly manipulate text and graphics, it works with the combination of HTML elements in a Web page, but it can control the browser, allowing the browser to manipulate text and graphics directly. In Java, you can manipulate text and graphics directly.
The difference between JavaScript and Java