Java Data types

Source: Internet
Author: User

Java Data Types


The Java integer constant is the int type by default, but there are two things to be aware of:

1. Assigning a small integer constant (within the range of Byte,short) to the Byte,short type, the system automatically treats the integer constant as a byte,short type.

2. When using a huge integer constant (out of the int range), Java does not automatically treat this integer constant as a long type. You need to add L or L (recommended L) after the integer constant.

The system automatically handles 127 as a byte type, allocating 1 bytes of storage space byte SMALL1 = 127;//system handles 127 as an int type, allocates 4 bytes of storage space int small2 = 127;//syntax error "the literal 214 7483648 of type int is out of range "long big1 = 2147483648;//correct, plus L is forced to use long type long big2 = 2147483648L;

Integer constants are represented in 3 ways: decimal (default), octal, hexadecimal.

Octal notation, starting with 0 int octalvalue = 011;//decimal 9//16 binary, starting with 0x or 0X int hexvalue = 0xa;//decimal 10

Java Data types

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.