Java Data types

Source: Internet
Author: User

1.Java data type (two types: base data type, reference type)

1.1 has 8 basic data Types

Byte,short,int,long,float,double,char,boolean

8 bit = 1 byte ( bytes )

1 kb=1024 Byte

1.2 cast

from low to high Turn: (Automatic conversion) no problem.

1.2.1 Two types must be compatible, and the target type is greater than the source type, for example:

Byte,char , and short types can all be promoted to int .

1.2.2 for an expression, the final result will be the same as the highest data type in the expression.

from high to low go: (cast) there is a problem.

If the data type of the converted value is greater than its target type, some information will be lost;

int x = 65;

char ch = (char) x;

Such statements will cause an error because the char type is less accurate than the int type, and the compiler cannot convert it automatically, only cast:

1.3 Reference type:

In addition to the 8 basic data types, it is the reference data type.

Including:

classes in 1.API, such as String,File , and so on

2. Arrays

3. custom classes, such as Cars,Student

4. objects are all reference data types

1.4 The reference type uses exactly the same scenario as the base data type

1. use as a type of attribute

2. Use the return value type as a method

3. use as a form parameter type for a method

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.