Java Data types

Source: Internet
Author: User

Java Data type:

In the Java domain , the basic data type variable is stored in the data itself , whereas the reference type variable holds the spatial address of the saved data.

When assigning a value to a char variable, use "when assigning a value to a string variable"

In Java, the default declaration of decimals is double type, such as: Double d=4.0

If the declaration: float x = 4.0 will be an error, you need to use the following notation: float x = 4.0f or float x = (float) 4.0

Where the F behind 4.0f is just to differentiate double, it doesn't mean any number.

Conditions for automatic type conversions:

The target type can be compatible with the source type, for example: Double is compatible with int, but char is incompatible with int

The target type is greater than the source type, such as a double with a length of 8 bytes and an int type of 4 bytes, so a variable of type double can directly hold data of type int, but in turn it cannot be

To force type conversions:

Such as:

double avg1=75.8;  int avg2=(int)AVG1; #强制把double转换为int

Casts can cause data loss

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