Let me tell you a story: A long time ago, there was a man named Netscape who was pregnant for ten months. He gave birth to a son and was very happy and named his son livescript. Livescript is very diligent, helping the uncle and aunt do a lot of work, and making a lot of money for his father. Suddenly one day, Sun gave birth to a son: Java, Java is very powerful, with a high popularity, and he is vaguely in ascending the throne. His father turned his eyes and thought: Java is going to go to God, I have to take the opportunity to make a decision! So he called his son, his mouth curled up, and a meaningful smile appeared, saying, "Son, look at how cool the name of Java is, you will take his surname from now on." So, from then on, JavaScript appeared in front of everyone, and the uncle and aunt were talking behind their backs: "Hey, this is not the illegitimate child of Java next door, would you ask him to help us do the work." In this way, after JavaScript changed its name, life was OK and took on a lot of work. Lao Netjing looked at his son, counting the money and smiling happily, complacent about his wisdom. "Haha, I just changed my name, the effect is really good, Java is indeed amazing. I have to let my son learn a little bit of Java, at least in his appearance, my old Net's blood still flows inside."
In a word: java and JavaScript are two different languages.
1 Language features:
1.1 Weak type:
JavaScript does not strictly distinguish data types when declaring variables, (var variable name), and is not as strict as Java (type: variable name). In other words, Javascript regards all beings as equals. In his eyes, everyone is human, but in Java's eyes, all beings are different, men, women, shemale, etc.
Based on this feature, JavaScript can often be written in a concise way than Java, such as function declarations.
1.2 Dynamic language:
Java cannot be changed after defining the length of an array, but JavaScript can do it. And java array can only put the same type, but javascript can add data of different data types into an array. It can be said that Java is more scheming, while Javascript is more flexible.
1.3 Scripting language:
Java and other background languages are all executed after compilation, but Javascript is executed while compiling.
2 Data Types
2.1 Basic data types:
Java has eight major data types: byte, short, int, long, float, double, char, and Boolean. It feels like JavaScript has sorted the above into three primitive types: number, string, and boolean. There are two special primitive types: null and undefined.
2.2 Variables
Java: Data type Variable name = value;
Javascript: var variable name = value; array
Java:
Type[] Array name=new Type[quantity];
Type[] Array name=new Type[]{element 1, element 2…};
Javascript:
var array name =[];
var array name = new Array();
3 functions:
Java: Return value type Function name (type parameter 1, type parameter 2…) {}
Javascript: function function name (parameter 1, parameter 2…) {}
The above is the similarities and differences between JavaScript and Java languages introduced to you by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support for my website!