📜  Java和JavaScript有什么区别

📅  最后修改于: 2020-10-27 01:28:45             🧑  作者: Mango

Java和JavaScript有什么区别

许多用户认为Java和Java脚本是相似的语言,或者它们是同一语言的两个不同名称。但是用户必须清除自己的疑问,即Java脚本和Java语言不是相似的语言,并且Java脚本与Java编程语言无关。之所以将脚本语言引入JavaScript的主要原因是Java编程语言在当时的鼎盛时期非常流行。为了利用Java编程语言中“ java”一词的流行优势,将其作为JavaScript引入。

为了了解Java和JavaScript语言之间的区别,让我们看一下它们之间的一些主要区别:

Java Language JavaScript Language
1. It is a Programming language. It is a scripting language.
2. Java is a pure Object Oriented Programming Language. JavaScript is Object-Based Language.
3. Java is a Standalone language. JavaScript is not a standalone language, as it needs to be integrated into an HTML program for execution.
4. Java is a strongly typed language, which means that the user has to decide the data type of the variable before declaring and using it.
Example “int a”, the variable “a” can store the value of integer type only.
JavaScript is a loosely typed language, which means that the user does not have to worry about the data-type of the variable before and after the declaration.
Example “var a”, the “a” variable can store the value of any data-type.
5. Java program should be compiled before execution. JavaScript needs to be integrated into the HTML program for the execution.
6. The web-browser is not required to run java programs. The web-browser is essential to run the JavaScript programs.
7. It is one of the complex languages to learn. It one of the easy languages to learn.
8. In Java, by utilizing the Multi-threading, users can perform complicated tasks. In JavaScript, user is not able to perform complicated tasks.
9. It requires a large amount of memory. It does not require that amount of memory.
10. Java programming language was developed by the “Sun Microsystems.” JavaScript programming language was developed by the “Netscape.”
11. In Java programming language, programs are saved with the “.java” extension. On the other hand, programs in JavaScript are saved with the “.js” extension.
12. Java is stored on the host machine as the “Byte” code. JavaScript is stored on the Host machine (client Machine) as the “source” text.

让我们看看如何用两种语言编写程序:

用Javaprint“ Hello World”的程序

class A
 { 
public static void main(String args[]){ 
    System.out.println("Hello World"); 
 } 
}

输出量

地狱世界

用JavaScriptprint“ Hello World”的程序




Welcome to JavaScript Tutorial

输出量