Difference: 1. JavaScript is object-based, and Java is object-oriented; 2. JavaScript does not need to be compiled before being sent to the client for execution, while java does; 3. Variable declarations in js use weak Type, Java uses strong typing; 4. js uses dynamic binding, Java uses static binding, etc.
The operating environment of this tutorial: windows7 system, javascript1.8.5&&java8 version, Dell G3 computer.
The difference between javascript and Java is mainly reflected in the following aspects:
1. JavaScript is object-based, and Java is object-oriented.
javascript is object-based, it is a scripting language, an object-based and event-driven programming language, so it itself provides a very rich set of internal objects for designers to use. Java is object-oriented, that is, Java is a true object-oriented language. Even when developing simple programs, objects must be designed.
2. JavaScript and Java are executed differently in the browser
javascript is an interpreted programming language, and its source code is sent to the client It does not need to be compiled before execution, but the character code in text format is sent to the client, that is, the javascript statement itself is downloaded along with the Web page and interpreted and executed by the browser.
The Java source code must be compiled before being passed to the client for execution. Therefore, the client must have an emulator or interpreter on the corresponding platform. It can be independent of the compiler or interpreter. Compile code for a specific platform.
3. JavaScript and Java code formats are different
Javascript code can be directly embedded in HTML documents and can be loaded dynamically. Writing HTML documents is like editing text files. Just as convenient, its independent file format is *.js.
Java is a format that has nothing to do with HTML. It must be loaded by referencing external media like HTML. Its code is saved in an independent document in the form of byte code. The format of its independent file is * .class.
4. The variables adopted by javascript and Java are different.
The variable declaration in javascript adopts weak type, that is, the variable does not need to be declared before use. Instead the interpreter checks its data type at runtime. Java uses strong type variable checking, that is, all variables must be declared before compilation.
5. JavaScript uses dynamic linking, and Java uses static linking.
Javascript uses dynamic linking, that is, JavaScript object references are checked at runtime. Java uses static binding, that is, Java object references must be made at compile time so that the compiler can implement strong type checking.
6. Different ways of operating text and graphics
Javascript does not directly operate text and graphics. It works together with the combination of HTML elements in the Web page. , but it can control the browser and let the browser directly process text and graphics. Java can directly operate on text and graphics.
7. JavaScript and Java are different products developed by different companies.
Javascript is a product of Netscape. Its purpose is to expand the functions of Netscape Navigator. An object-based and event-driven interpreted language that can be embedded in Web pages;
and Java is a new generation of object-oriented programming language launched by SUN Microsystems, which is particularly suitable for Internet application development. In fact, the original name of javascript was not javascript, but LiveScript. The "Java" in the name was authorized by SUN Microsystems.
[Recommended learning: javascript advanced tutorial]
The above is the detailed content of What is the main difference between java and javascript. For more information, please follow other related articles on the PHP Chinese website!