Java's data types fall into two categories:
1. Basic data types and reference types
Basic data types are: Integer, float, Boolean
Reference types include: Object, interface, array, NULL
The base data type holds the value of the variable, and the reference type holds the address of the variable.
For example: int[] A = new int[4]; At this point the value of variable A is the address of the array that is stored on the stack, and the specific array values are stored on the heap. So there is no concept of pointers in Java, and the assignment of objects is the delivered address.
2. Basic data type:
2.1 Integral type
Integer has a byte short int long char, denoted by 8, 16, 32, 64, 16bits, respectively. In some places, char may not be included in an integer category, but essentially a char type is a subset of Int. The width of an integral type should not be considered as the amount of memory space occupied by integers, but should be understood as the behavior of variables or expressions defined as integral types. The JVM is free to use the memory space of any size that they want, as long as the type behaves in accordance with the specification. A byte short int long is signed, denoted by the 2 complement (s-complement). Char, in 16-bit notation, is unsigned and represents the UTF-16 encoding set.
A byte is represented by 1 bytes of 8 bits. The values range from: [-128, 127].
Short is represented by a 16-bit value range of: [-2^15, 2^15-1]int, [-2^31, 2^31-1].long bits, [-2^63, 2^63-1, default = 0l].char-Bits, [0, 65535], [0, 2^16-1], from ' \u0000 ' to ' \uffff '. Unsigned, the default value is ' \u0000 '.
Public classintegral type {byteb; Shorts; inti; Longl; CharC; Booleanbool; Public Static voidMain (string[] args) {integral type a=Newintegral type (); System.out.println ("B =" +a.b); System.out.println ("s =" +A.S); System.out.println ("I =" +A.I); System.out.println ("L =" +A.L); System.out.println ("C =" +A.C); System.out.println ("BOOL =" +A.bool); }}
Results:
2.2 Floating-point type
Float-A-bit representation
A double 64bit indicates
float A = 10.2f/f
Double d = 10.2d/d
Default value: 0.0
2.3 Boolean
The Boolean type has only two values of true and false, and the default is False.
3. Conversions between basic data types
Start by arranging the 7 types in the following order:
byte < (SHORT=CHAR) < int < Long < float < double (can be auto-completed if small to large, and must be cast from large to small.) the same type of short and char two must also be cast. )
Conversions are divided into automatic conversions and casts. For an automatic conversion (implicit), no action is required, and the coercion of type conversions requires an explicit conversion, that is, using the conversion operator (type). Start by arranging the 7 types in the following order:
4. Automatic type promotion in an expression
In addition to assignment, some type conversions can occur during expression evaluation. In an expression, the type promotion rule is as follows:
"All Byte/short/char are promoted to int.
"If there is an operand of long, the entire expression is promoted to long. The same is true for float and double.
Java Data types