Although JavaScript is closely related to Java, it is a different product developed by two companies. Java is a new-generation object-oriented programming language released by SUN, which is especially suitable for Internet application development. JavaScript is a product of Netscape, and its purpose is to expand the Netscape Navigator function, developed an object-and event-driven explanatory language that can be embedded into Web pages, its predecessor is Live Script, and Java's predecessor is the Oak language. The similarities and differences between the two languages are compared as follows:
1. Object-based and object-oriented
Java is a real object-oriented language. Even a simple program must be designed. JavaScript is a scripting language that can be used to create complex software that is unrelated to the network and interacts with users. It is a programming language Based on Object-Based) and Event-driven Event Driver. Therefore, it provides a wide range of internal objects for designers.
2. Interpretation and compilation
The two languages are executed in different ways in their browsers. Java source code must be compiled before it is passed to the client for execution. Therefore, the client must have a simulator or interpreter on the corresponding platform, it can use compilers or interpreters to compile code independently from a specific platform.
JavaScript is an interpreted programming language. Its source code does not need to be compiled before it is sent to the client for execution. Instead, it sends the character code in the text format to the client for interpretation and execution by the browser.
3. Strong variables and weak Variables
The variables used by the two languages are different. Java uses a strongly typed variable check, that is, all variables must be declared before compilation. For example:
|
Integer x; String y; X = 1234; X = 4321; |
X = 1234 indicates an integer, and Y = 4321 indicates a string. The variable declaration in JavaScript uses its weak type. That is, variables do not need to be declared before use, but the interpreter checks their data types at runtime, such:
The former indicates that x is its numeric variable, while the latter indicates that y is a numeric variable.
4. Different Code formats
Java is an HTML-independent format. It must be loaded by referencing external media in HTML, and its code is saved as byte code in an independent document. JavaScript code is a text character format that can be directly embedded into HTML documents and loaded dynamically. Compiling HTML documents is as convenient as editing text files.
5. Different embedding Methods
In HTML documents, the two programming languages have different identifiers. JavaScript uses the identifiers, while Java uses....
6. Static and Dynamic Association
Java uses static concatenation, that is, Java object reference must be carried out during compilation, so that the compiler can implement forced type check. JavaScript uses dynamic concatenation, that is, JavaScript Object Reference is checked at runtime. If it is not compiled, the object reference check cannot be implemented.