Data types in Java

Source: Internet
Author: User

Data types in Java fall into 2 categories: reference data types (interfaces, classes, arrays), basic data types (four categories, total eight) 650) this.width=650; "Src=" Http://img.baidu.com/hi/jx2/j_0015.gif " alt= "J_0015.gif"/>

What is the difference between the two categories in the first analysis?

The basic data type is declared to give a memory space to store the value of the variable, whereas a reference data type declaration, like a pointer, points to an address, and the address is the stored value.

The basic data types are described below:

650) this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0001.gif "alt=" J_0001.gif "/>

Shaping: The default number of bytes

BYTE 1

Short 2

int 4√

Long 8

Floating point type:

Float 4

Double 8√

Character type:

Char 2

Boolean type:

Boolean 1

And to be aware,

In the process of the operation:

Byte, short, char will turn int to long

Float will turn into double

Byte B1=2;byte b2=4;//This is because the right side is a constant, if in the range of byte, compile will not error

Byte b3=b1+b2;//This error, because the right side is a byte type, the operation or automatic upward transformation into an int type, and the left is a byte type, large turn small, downward transformation, there will be loss of precision problems.

byte b3=2+4; This will not be an error, the reason is the same as the first, the constant addition minus, the result is a constant, if the value of the result in the byte range, will not error


This article is from the "Stone on the Road" blog, please be sure to keep this source http://xiashitou.blog.51cto.com/10853136/1946486

Data types in Java

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.