Differences between Java and JavaScript

Source: Internet
Author: User

Friends who often access the Internet must know the Javascript scripting language, because many homepages have such an identifier, which is used in the middle to compile the Javascript scripting language code. We also know that there is a network programming language ?? Java. Many people think that JavaScript is a Java-based programming language. If you think so, It is wrong. Java and JavaScript are two different products developed by two different companies. Java is a new-generation object-oriented Network Programming Language launched by Sun. It is designed to maximize the use of the network and is especially suitable for Internet application development. Its predecessor is the oak language; while Javascript is a product of Netscape, the objective is to expand the functions of the Netscape browser. It is developed and integrated in the Netscape browser. It is an explanatory language that can be embedded into web pages, based on objects and event-driven, its predecessor is live script. The following is a comparison between Java and javascript:

I. Object processing and application are different.

Java is a real object-oriented language. Even simple programs must be designed.

Javascript is a scripting language. It is an object-and event-driven programming language. Therefore, it provides a wide range of internal objects for program designers.

Ii. Different Code formats

Java is an independent HTML-independent format. The reference Java program in HTML must be loaded as a reference to external media, and its code is saved in the form of byte code in an independent document.

JavaScript code is closely linked to HTML documents. It is directly embedded into HTML documents. It is a text character format and can be dynamically loaded.

3. Define variables in different forms.

Java uses a strongly typed variable check, just like the C language. All variables must be declared before compilation, and no variable with no value assigned can be used. For example:

Int X;
X = 1234;
Char y = 'F ';

X = 1234 indicates an integer, and y = 'F' indicates a character.

Javascript variables do not need to be declared before they are used. They are checked for weak type variables, and the interpreter checks their data types at runtime. For example:

X = 1234; X indicates that X is a numeric variable.
Y = 'F'; indicates that Y is a variable of variable type.

This is similar to programming in BASIC language.

4. Different execution methods

Before the source code of Java is passed to the client for execution, it must be compiled to form an independent byte code and then executed through the simulator or interpreter on the corresponding platform of the client, 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 and is interpreted and executed by the client browser.

5. Different Ways of embedding a browser

When these two languages are embedded in HTML documents, their identities are different ?? Javascript is used for identification, while Java is used for identification. You can refer to the view source code function of the browser.

In short, these two languages are useful on the Internet, but we need to clarify their differences. Generally, there are many javascript programs on a home page, but Java programs should be as few as possible. It is best not to exceed two ?? Because it affects the speed of homepage display.

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.