官术网_书友最值得收藏!

3.1 Data Types Overview

Java is known as a strongly typed language. It means that Java is a language that will only accept specific values within specific variables or parameters. Some languages, such as JavaScript, are weakly typed languages. This means that you can readily store whatever you want into a variable. Here is an example of the difference between strongly typed and weakly typed languages:

JavaScript (weakly typed)(Java腳本)

1: var x; // Declare a variable

2: x = 1; // Legal

3: x = "Test"; // Legal

4: x = true; // Legal

Java (strongly typed)

1: int x; // Declare a variable of type int

2: x = 1; // Legal

3: x = "Test" // Compiler Error

4: x = true; // Compiler Error

In a weakly typed language, such as JavaScript, you simply declare a variable without assigning it a type. In a strongly typed language, such as Java, you must give a variable a type when you declare it. Once you’ve declared a variable to be that type, it will remain of that type definitely and will only accept values that are within that types range. You should note that this is one of the many differences between Java and JavaScript. Despite their names, they have very little to do with one another.

Java是一種強(qiáng)類型編程語言。當(dāng)聲明一個(gè)變量的時(shí)候,必須給出該變量的類型。一旦給定了類型,所賦予的值必須在相應(yīng)的精度內(nèi)。

Now that we know that Java is a strongly typed language, you can probably see how important it is to know what data types there are in Java. There are 9 data types in Java, 8 primitive types and a reference type. First, let’s look at primitive types and then we’ll move along to reference types.

Java是強(qiáng)制類型檢查的語言。Java中有9種數(shù)據(jù)類型,其中8種是基本類型,一種是引用類型。

主站蜘蛛池模板: 库伦旗| 吉林市| 庆阳市| 琼海市| 定西市| 汕头市| 莆田市| 宁武县| 墨玉县| 五家渠市| 秦安县| 祁东县| 阿克| 曲阳县| 玉屏| 井研县| 金坛市| 康保县| 烟台市| 宁强县| 绥阳县| 四子王旗| 乌拉特前旗| 留坝县| 长宁区| 舞钢市| 华容县| 九寨沟县| 家居| 砀山县| 邛崃市| 麟游县| 崇明县| 江安县| 浮山县| 阿克陶县| 沁水县| 当涂县| 济源市| 尼木县| 沅陵县|