Data | data type
1. Simple data type
Logical Type Boolean
Text type char,string (special type)
Integer type Byte,short,int,long
Floating-point type Double,float
Boolean two values: True and False
Char 16-bit unsigned (non-positive) Unicode characters must be enclosed in single quotes (')
eg: ' \ t ' represents a tab character
' \u???? ' represents a special Unicode character???? should be replaced in strict accordance with the 4 16 numbers.
String is not a simple data type but a class (class) that is used to represent a sequence of characters. The character itself conforms to the Unicode standard
The backslash notation for the char type above applies to string.
Different from C and C + +, string cannot end with ' \o '. (originally to write ' \ 0 ', but it is not show, no recruit son, use O to replace it ~ ~)
byte short int long
Follow the data directly with a letter "L". L means this is a long value. In the Java programming language L is equally valid in both uppercase and lowercase, but because lowercase l is easy to confuse with number 1, using lowercase is not a wise choice.
Length and range of values for integer data
--------------------------------------------------------------------------------------------------------------- -------
Length data type numeric range
--------------------------------------------------------------------------------------------------------------- -------
8 bits Byte-2 (7) ~2 (7)-1
Bits Short-2 (15) ~2 (15)-1
Bits Int-2 (31) ~2 (31)-1
Bits Long-2 (63) ~2 (63)-1
--------------------------------------------------------------------------------------------------------------- ------
Float double
The value contains the decimal point or exponent, or the letter F or F (float) after the number, D or D (double)
The length and range of values of floating-point data
--------------------------------------------------------------------------------------------------------------- -------
Length data type numeric range
--------------------------------------------------------------------------------------------------------------- -------
Bits float 1.401e-45~3.402e+38
The bits long 4.94e-324~1.79e+308d
--------------------------------------------------------------------------------------------------------------- -------
2. Declaration and assignment of simple data type variables
public class assign{
public static void Main (string[] args) {
int x,y; DECLARE int variables
float z=3.414f; Declare and assign float variable
Double w=3.1415; Declare and assign double variable
Boolean truth=true; Declare and assign Boolean variable
char c; DECLARE character variable
String str; DECLARE String variable
String str1= "Bye"; Declare and assign String variable
c= ' A '; Assign value to char variable
Str= "Hi out there!"; Assign value to String variable
x=6;
y=1000; Assign values to int variable
...
}
}
Here are some illegal assignment statements:
y=3.1415926; is isn't an int. Requires Casting and decimal would be truncated
w=175,000; The comma symbol (,) cannot appear
truth=1; A common mistake made by ex-c/c++ programmers
z=3.14156; Can ' t fit double into a Float