Difference: 1. JavaScript is interpreted and executed by the browser, while Java programs are compiled and executed; 2. JS is an object-based scripting language, and Java is a true object-oriented programming language; 3. , JS is a weakly typed language, and Java is a strongly typed language; 4. The code format and the way of embedding HTML documents are different.
The operating environment of this tutorial: windows7 system, javascript1.8.5&&java8 version, Dell G3 computer.
Java is an object-oriented programming language developed by Sun Corporation and is suitable for network application development. JavaScript (JS for short) was originally inspired by Java and started to be designed. One of the purposes is to "look like Java", so the syntax is similar to Java, and some names and naming conventions are also derived from Java.
But in fact, JavaScript is very different from Java in other aspects except that it is somewhat similar to Java in syntax and as mentioned above for marketing purposes. In the following points:
1) JavaScript is interpreted and executed by the browser, while Java programs are compiled and executed.
2) JavaScript is an object-based scripting language, which provides a wealth of built-in objects for developers to use directly; Java is a true object-oriented programming language, regardless of the simplicity and complexity of the developed program. No, both must design objects.
3) JavaScript is a weakly typed language. When declaring a variable, you do not need to declare the type of the variable, or even use the variable directly without declaring the variable; Java is a strongly typed language, and the variable must be declared before use and must be declared. type.
4) The code format and the way to embed HTML documents are different:
Java code must be compiled into a bytecode file using the corresponding compilation tool, and HTML documents must be embedded using <applet> ;...</applet>
tag is embedded in the bytecode file; JavaScript code is a text character format, and the <script></script>
tag is used to embed the HTML document, in which you can directly Embed JavaScript code or JavaScript script files.
[Related recommendations: javascript learning tutorial]
The above is the detailed content of What are the differences between java and javascript?. For more information, please follow other related articles on the PHP Chinese website!