Java long data type-materials learned online, long data type

Source: Internet
Author: User

Java long data type-materials learned online, long data type
Java long data type bit signedJavaRaw data type. When the calculation result of an integer may exceedintThe range of data types.

longThe data type range is-9,223,372,036,854,775,808To9,223,372,036,854,775,807(-2^63To2^63-1).

longAll integers in the Data Type range are calledlongType.longInteger constants of the type are always in uppercase.LOr lower caselEnd.

UselongExample of an integer literal:

long  num1 = 0L; long  num2 = 4L; long  mum3  = -3; long  num4 = 8; long  num5 = -1L;
JavaLong literal

longThe 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

WhenlongThe type of integer literal is assignedlongFor 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:intTolongThe Type assignment is valid because it is stored inintAll values in the variable can be stored inlongType variable. However, it may not be becauselongType data RatiointThe type range is large. Therefore, you cannot simply storelongThe value in the variable is assignedintVariable. There is a possibility of value overflow.

TolongAssign the variable valueintVariable, please use "Conversion" in Java, as shown below:

num1 = (int)num2;
Java

Java hasLongClass, which defines two constants to represent long data typesLong.MAX_VALUEAndLong.MIN_VALUE.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.