What does JavaScript have to do with the Java language? The similarities and differences between the two languages _java

Source: Internet
Author: User

Although JavaScript is closely related to Java, it is a different two product developed by two companies. Java is a new generation of object-oriented programming languages introduced by Sun. Especially suited for Internet application development, and JavaScript, a joint product of sun and Netscape, is an object-oriented and event-driven interpretive language that can be embedded in Web pages for the purpose of extending Netscape Navigator functionality. And its predecessor is live Script, and Java's predecessor is the Oak language. The following is a comparison of the similarities and differences between the two languages:

(1) object based and object oriented

Java is a truly object-oriented language, and you must design objects even if you are developing a simple program. JavaScript is a scripting language that can be used to create complex software that is not relevant to the network and enables interaction with the user. It is an object-based (object Based) and event-driven programming language (Driver). As a result, it provides a very rich internal object for designers to use.

(2) Interpretation and compilation

The two languages do not perform the same way in their browsers. Java source code must be compiled before it is passed to the client, so there must be a * * or interpreter running on the platform on the client. It can be implemented independently of a particular platform through a compiler or interpreter and is not bound by compiled code. JavaScript is an interpreter programming language whose source code does not need to be compiled before it is sent to the client, but instead sends the text-formatted character code to the client for interpretation by the browser.

(3) Strong and weak variables

The variables used in both languages are different. Java uses strongly typed variables, that is, all variables must be declared before they are compiled. Such as

Integer x;
String y;
x=1234;
x=4321;

Where the x=1234 description is an integer, the y=4321 description is a string.

In JavaScript, a weak type means that a variable is not required to be declared before it is used, and that the interpreter checks its data type at run time, as

x=1234;
Y= "4321";

The former indicates that x is a numeric variable, while the latter indicates that Y is a character variable.

(4) Code format is not the same

Java is a HIML-independent format that must be loaded in the form of a byte code in a separate document, as in the case of an external media reference in HTML. JavaScript code is a text character format that can be embedded directly in an HTML document and dynamically loaded. Writing an HTML document is as easy as editing a text file.

(5) The embedding method is different

In HTML documents, the identities of the two programming languages are different, and JavaScript uses "<script language=" JavaScript ">" to identify them, while Java uses "<applet>...</applet > "to identify.

(6) Static and dynamic joint-edit

Java uses a static binder, that is, Java object references must be made at compile time to enable the compiler to implement strong type checking. JavaScript uses a dynamic binder, which is a JavaScript object reference that is checked at run time, and cannot be checked for object references without compilation.

JavaScript is embedded in the HTML and becomes part of the HTML document.

What is the relationship between JavaScript and the Java language described in the small series? The similarities and differences between the two languages, hope to help everyone, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.