1. Basic data types
Java is a strongly typed language, and each variable must declare its type.
. Java 's data types fall into two main categories: the base type (primitivetype) and the reference type (reference type )
. 3 classes of 8 Basic data Types are defined in Java
. Logical Type-Boolean
. Text Type- Char
. Numeric Type- byte, short, int, long, float, double
Note: The size of the reference data type is uniformly 4 bytes, and the address of the reference object is recorded!
2. Integer variables
An integer is used to denote a numeric value without a decimal part, which allows a negative number.
scope and operation of integral type Java the code is machine-independent, which is exactly Java One of the reasons why the program has a strong transplant capability.
|
Type |
Occupy Storage space |
Table Count Range |
|
Byte |
1 bytes |
-128~127 |
|
Short |
2 bytes |
-215 ~ 215-1 (-32768~32767) |
|
Int |
4 bytes |
-231 ~ 231-1
( -2147483648~2147483647) about + billion |
|
Long |
8 bytes |
-263 ~ 263-1 |
three representations of the Java-language integer constants:
decimal integers, such as:-500, 0.
an octal integer that requires a 0 start, such as:015.
hexadecimal number, requires 0x or 0X beginning, such as:0x15 .
the integer constant for the Java language defaults to type int , declaring that a long constant can be followed by an ' l ' or ' L ' , such as:
Long a = 55555555; no error, within the range of Int ( within billion ).
Long B = 55555555555;// does not add an error, it has exceeded the range represented by Int. Error:
The literal 55555555555 of type int is out of range
There is no unsigned type in Java
3. Code hinting
Public classtestdatatype{ Public Static voidMain (string[] agrs) {intA = 100;//default is 10 binary number intb = 010;//8 binary intc = 0x10;//16 binarySystem.out.println (a); System.out.println (b); System.out.println (c); System.out.println (Integer.tobinarystring (a)); //convert to 2 binarySystem.out.println (Integer.tooctalstring (a));//Convert to 8 binarySystem.out.println (Integer.tohexstring (a));//convert to 16 binary byted = 100;//if the size of the data does not exceed Byte/short/char's stated range, it can be automatically transformed LongE = 11123213232L; }}
"Java" java_06 basic data types