Since the release of Java, primitive data types is an important part of the Java language, this paper describes in detail under basic types for each specific use and limitations.
The following is the translation:
int someNumber = 10;
Of course, like all basic types, Integer has its own limitations. Since it is only 32, so that the range -2147483648 to 2147483647. This figure great thing! Of course, we can confirm the following tips in using DrJava interactive panel:
Integer.MAX_VALUE // Prints 2,147,483,647
Integer.MIN_VALUE // Prints -2,147,483,648
Naturally, for the simple calculations, int is the most common type integer. If you need a larger range of numbers, please refer to the following long.
double someNumber = 110.55;
Need to be reminded that the float is actually real. In other words, the double precision floating point decimal point.
Double.MAX_VALUE // Prints 1.7976931348623157E308
Double.MIN_VALUE // Prints 4.9E-324
It should be noted that the negative index indicates the very small number, but not a very large negative number. So here's the range is not exactly the same as integer.
char someCharacter = 'f';
Java中所有的字符都用单引号表示。同时,双引号用来表示字符串。我们稍后会讨论字符串。
Character.MAX_VALUE // Prints '???'
Character.MIN_VALUE // Prints ''
为了让这个范围有意义,我们可以将结果转换成整数(稍后会更多地介绍):
(int) Character.MAX_VALUE // Prints 65535
(int) Character.MIN_VALUE // Prints 0
可见,char类型是Java中唯一的无符号类型。换句话说,字符的取值范围为0到65535,每个值映射到特定的字符。如果需要创建该范围之外的字符,可以将一对字符组合起来。参见“在Java中反转字符串”(https://therenegadecoder.com/code/reverse-a-string-in-java/)这篇文章中的例子。
byte someByte = 20;
同样,可以利用下面的代码片段来确认byte类型的取值范围:
Byte.MAX_VALUE // Prints 127
Byte.MIN_VALUE // Prints -128
根据我的经验,byte类型在读取和处理原始数据时非常有用。但是一般而言,我们不会使用它,因为取值范围太小了。
short someNumber = 11;
short类型的取值范围也只有整数的一半,我们可以用下述代码确认:
Short.MAX_VALUE // Prints 32767
Short.MIN_VALUE // Prints -32768
在实际应用中,short只有65546个可能的值。在内存空间和磁盘空间受限的情况下,我们会使用byte和short。但在其他情况下,在定义整数时默认使用int更为安全。
long someBigNumber = 1013401346173L;
The following code can see how much 64-bit value:
Long.MAX_VALUE // Prints 9,223,372,036,854,775,807
Long.MIN_VALUE // Prints -9,223,372,036,854,775,808
Perhaps, long it may be used to calculate the distance light travels in a certain period of time. About 30 million meters of light propagating in one second. If you are writing a program to track the distance the light traveled, then 7 seconds after it is beyond the scope of the class of type int, long and about 975 types can be calculated. Do not believe me? This calculation can look gist (https://gist.github.com/jrg94/820d3f0f482dd19f0170964346381df0) in.
float someNumber = 11.4f;
type float range as follows:
Float.MAX_VALUE // Prints 3.4028235E38
Float.MIN_VALUE // Prints 1.4E-45
Seen, 32-bit floating-point range and precision are considerably smaller. If you do not double precision, while saving half the space, you can select the type float.
boolean isBool = true;
Some special Boolean type, unlike other basic types as not a numerical value they represent. In fact, MAX_VALUE and MIN_VALUE techniques previously used can not be used here. Instead, it represents the true or false, that is, true and false.
Thermal paper recommended