Java Basic data types

Source: Internet
Author: User

The data type represents the different types of values to store in the variable.

One, the Java language provides eight kinds of basic data types. Six types of numbers (four integers, two floating-point types), one character type, and one Boolean type.

1, byte

    • The byte data type is a 8-bit, signed, integer in binary complement notation;
    • The byte type is used to save space in large arrays, mainly in place of integers, because the byte variable occupies only one-fourth of the int type;
    • The default value is 0, the minimum value is 128 ( -2^7), and the maximum value is 127 (2^7-1);
    • The corresponding encapsulation class is Byte;

2. Short

    • The short data type is a 16-bit, signed integer with a binary complement representation;
    • The short data type can also save space as Byte. A short variable is one-second of the space occupied by the int variable;
    • The default value is 0, the minimum value is 2,147,483,648 ( -2^31), and the maximum value is 2,147,483,647 (2^31-1);
    • The corresponding package class is short;

3, int

    • The int data type is a 32-bit, signed integer with a binary complement representation;
    • The generic integer variable defaults to the int type;
    • The default value is 0, the minimum value is 2,147,483,648 ( -2^31), and the maximum value is 2,147,483,647 (2^31-1);
    • The corresponding encapsulation class is Integer;

4, long

    • The Long data type is a 64-bit, signed integer with a binary complement representation;
    • This type is mainly used on systems that need to compare large integers;
    • The default value is 0L, the minimum value is 9,223,372,036,854,775,808 ( -2^63), the maximum value is 9,223,372,036,854,775,807 (2^63-1);
    • The corresponding encapsulation class is Long;

5, float

    • The float data type is a single-precision, 32-bit, IEEE 754 compliant floating-point number;
    • The direct assignment must be preceded by a number F or F.
    • Default value 0.0f;
    • The corresponding package class is Float;

6, double

    • The double data type is a dual-precision, 64-bit, IEEE 754-compliant floating-point number;
    • The default type of floating-point number is double type;
    • Default value 0.0d;
    • The corresponding encapsulation class is Double;

7, Boolean

    • The Boolean data type represents one bit of information;
    • Only two values: true and false;
    • The default value is false;
    • The corresponding encapsulation class is Boolean;

8, Char

    • The char type is a single 16-bit Unicode character;
    • The default is \u0000;
    • The corresponding package type is Character;

Where we can use the corresponding encapsulation class to get the corresponding information:

(1) Bits number of basic types: XXX. SIZE;

(2) Minimum value: XXX. Min_value;

(3) Maximum value: XXX. Max_value;

Second, constant, we do not change the value of the program in operation.

Constants are defined using the final keyword, for example:

final duble pi=3.1415926;

The defined constant PI will not be able to change its value by any action during the run of the program.

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.