The difference between Java and JavaScript

Source: Internet
Author: User

When it comes to JavaScript, people tend to think of Java, and while JavaScript is closely related to Java, Java is a much more complex programming language than JavaScript, and JavaScript is a language that is fairly easy to understand. JavaScript creators can be less focused on programming skills, so many Java features are not supported in Java Script, and they are two different products developed by two companies. Java is a new generation of Sun's object-oriented programming language, especially for Internet application development, and JavaScript is the product of Netscape, the purpose of which is to extend Netscape Navigator functionality, The development of an object-oriented and event-driven interpretive language embedded in a Web page, formerly live Script, and Java's predecessor was the Oak language. The following compare the similarities and differences between the two languages as follows:

1, object-based and object-oriented

Java is a real object-oriented language, even if you are developing a simple program, you must design the right. JavaScript is a scripting language that can be used to create complex software that is unrelated to the network and interacts 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's source code must be compiled before it is passed to the client, so that the client must have an emulator or interpreter on the platform that implements the binding of compiling code independent of a particular platform through a compiler or interpreter. JavaScript is an interpretative 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 variable and weak variable

The variables adopted in the two languages are different. Java uses strongly typed variables to check that 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. A variable declaration in JavaScript, using its weak type. That is, the variable is not declared before it is used, but rather the interpreter checks its data type at run time, such 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, the code format is not the same

Java is an HTML-independent format that must be loaded through a reference to an external media like HTML, and its code is stored in a separate document as a byte code.

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 not the same

In HTML documents, the two programming languages have different identities, JavaScript uses <Script>....</Script> to identify, and 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.

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.