8 native data types in 1.java
1) Shaping: Use int to denote
2) Byte type: using byte notation
3) Short integer:
4) long shaping: use long to indicate
5) Single-precision floating point type: using float. The so-called floating point, refers to a small tree, also known as a real number, such as 1.2
6) Double-precision floating-point type: Using a double representation. The data range represented by a double-progress floating-point type is larger than the single-precision floating-point
7) Character type: Use char to indicate. (char is an abbreviation for character) the so-called character is a single character representation, such as the letter A,
Or Chinese sheets, surrounded by single quotation marks, such as Char a= ' B '; Char b= ' Zhang ';
8) Boolean type: Use Boolean notation.
public class varible2{public void Main (string[] args) { double a=1.2; System.out.print (a); Float a=1.2;//This line of code compilation error System.out.print (a);} }
2. Native datatype trap (pitfall of primitive data type)
Float a=1.2
Compile error, find double, need float
Cause: All floating-point types in Java are type double by default. You cannot assign a value of type double to a variable of type float.
It is not possible even if the value of the double type is within the range of type float. In summary, the success assignment depends on the value type on the right side of the equals sign
The variable type is identical to the left of the equals sign.
3. How to assign the value of a double type to a variable of type float, the answer is
1) Force type conversion to cast a value of type double to float type.
Coercion type conversion syntax: type variable name = (type) variable value; float a= (float) 1.2;
2) Using the Java language support, float a=1.2f;
4. Variables need to be assigned before use,
int A;print (a);
A variable must declare its type before it can be used
A;print (a);
The 5.int type cannot be assigned to a short type: a range-wide value cannot be assigned to a type variable of a small range, but only by forcing a type conversion.
You can assign a value of type short to a variable of type int with a large range.
Javase native data type (iv)