Java Basic data types

Source: Internet
Author: User

Data types in Java are divided into basic data types (primitive type) and reference data types.

    1. There are 8 kinds of basic data types: 4 integer, 2 float, 1 character types for Unicode encoded character cells, char and 1 Boolean types for true truth.
    2. Reference data types are divided into: classes, interfaces, arrays.

This article mainly describes the basic data types.

# integral type

An integer is used to denote a numeric value without a decimal part, which allows a negative number. Java provides 4 types of data, as shown in the following sections.

In the case of the byte type, the values of the maximum and minimum values are described, and the remaining integral types are similar.
BYTE has 8 bits (where the first bit indicates the sign bit, 0 is positive, 1 is negative), a total of 256 (28) number, divided into positive and negative, is 0 ~ +127 and 1 ~ 128 each 128 numbers.
The maximum value is 0111 1111 and the result is 27-1=127
The minimum value is 1000 0000 and the result is-128

The long integer value has a suffix of l, for example: 4000000000L. If you define this: long num = 4000000000, then the compiler will error: the literal 4000000000 of type int is out of range. It is shown that if the declared integer number does not have a type suffix, it defaults to the int type, and if it is a valid int type, it will be converted to a long type again at long num = a value. So the correct approach should be: long num = 4000000000L;

In Java you can use binary (since Java 7), octal and hexadecimal represent integers.
Prefix the value with:
0B represents a binary value: int x = 0b1001; // 9
0 denotes octal value: int x = 010; // 88 binary is easy to confuse and is not recommended for use.
0x denotes hexadecimal value: int x = 0xCAFE; // 51966

Java Basic 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.