Java Base 1_java data type

Source: Internet
Author: User

One. Java data types are divided into

1. Native data types

Also called basic data type, divided into shaping, floating-point type, character type, Boolean type. There are byte,short,int,long in shaping, floating-point type has float,double, character type has char, Boolean type has Boolean.

2. Reference data types

Includes class, interface, array

Two. Constants and variables

A constant is the amount of value that does not change, and a variable is the amount to which the value can vary.

Three. Declaration and initialization of variables

Example: int A;

a=0;

int b=0;

Four. Size of data type

In memory, the Byte,boolean type of data accounts for 1 bytes, or 8 bits;

The data of the Short,char type is 2 bytes, i.e. 16 2 binary bits;

The data of the Int,float type is 4 bytes, i.e. 32 2 binary bits;

The data for the long,double type is 8 bytes, or 64 2 binary bits.

Five. Type conversion

Type conversions are divided into forced type conversions and automatic type conversions.

When a type with a small precision is assigned to a variable with a high precision, it will be converted automatically, and the precision can be lost if the assignment of high precision to a variable with small precision requires forced type conversion.

Example: int i = (byte) 1; That's right

float a= 1; Correct, 1 The default is int type

float b=1.0; Error, 1.0 The default is double type, precision is higher than float, should be float b=1.0f;

int x = 5.5; Error, mandatory type conversion required, int x = (int) 5.5;

Java Base 1_java data type

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.