Java long data type-materials learned online, long data type
Java long data type bit signedJava
Raw data type. When the calculation result of an integer may exceedint
The range of data types.
long
The data type range is-9,223,372,036,854,775,808
To9,223,372,036,854,775,807
(-2^63
To2^63-1
).
long
All integers in the Data Type range are calledlong
Type.long
Integer constants of the type are always in uppercase.L
Or lower casel
End.
Uselong
Example of an integer literal:
long num1 = 0L; long num2 = 4L; long mum3 = -3; long num4 = 8; long num5 = -1L;
JavaLong literal
long
The literal value of the type can be expressed in octal, hexadecimal, and binary formats. For example,
long num1;num1 = 25L; // Decimal format num1 = 031L; // Octal formatnum1 = 0X19L; // Hexadecimal format num1 = 0b11001L; // Binary format
Java
Whenlong
The type of integer literal is assignedlong
For variable types, the Java compiler checks the value to be allocated and ensures that it is within the range of long data types; otherwise, a compilation error occurs.
Note:int
Tolong
The Type assignment is valid because it is stored inint
All values in the variable can be stored inlong
Type variable. However, it may not be becauselong
Type data Ratioint
The type range is large. Therefore, you cannot simply storelong
The value in the variable is assignedint
Variable. There is a possibility of value overflow.
Tolong
Assign the variable valueint
Variable, please use "Conversion" in Java, as shown below:
num1 = (int)num2;
Java
Java hasLong
Class, which defines two constants to represent long data typesLong.MAX_VALUE
AndLong.MIN_VALUE
.