3.5 Summary
That’s it for data types in Java. Just remember that Java is a strongly typed language. So much so, in fact, that you’ll learn these data types in a big hurry if you use Java very much at all. For those of you coming from a C++ type background, you’ll probably notice right away that Java is even more strongly typed than C++. For example, no more assigning 1 to a boolean variable. In Java, booleans are true or false - nothing else. Most of the information here is probably review/common sense if you’ve done any sort of programming at all. The most important thing for you to get out of this is to remember that Java is strongly typed.
As you will already know a variable is a value in a program which can be changed, this value is then used in some way by the program. For example, if a program were to ask the user for their age then print out how old they would be in 10 years time the program would store the age as a variable and then add 10 to it.
In Java variables are declared with the following syntax(语法):
data_type variable_name;
The data_type can be from the simple types or from user defined types (which will be covered in later tutorials).
The simple types are:
byte, short, int and long. All these types hold integer numbers of varying minimum and maximum sizes.
float and double which hold floating point numbers, again with different minimum and maximum values.
char is used to hold the value of characters.
boolean variables are either true or false.
byte, short, int和long,这些类型都存储具有不同范围的最大值和最小值的整数。
float和double存储浮点数字,同样具有不同的最小值和最大值。
char用来存储字符的值。
boolean变量为真值或假值。