<java Basic > data Type conversion <5>

Source: Internet
Author: User

The process of changing a value from one type to another type when a type is converted.
converting from a low-precision data type to a high-precision data type never overflows and is always successful.
The conversion of high-precision data types to low-precision data types will inevitably result in information loss and possibly failure.
There are two ways to convert data types, implicit type conversions and explicit type conversions (/////* These two symbols represent annotations):
implicitly-typed conversions:
conversions from low-level types to advanced types are performed automatically, and programmers do not need to do anything, and this type of conversion is called implicit conversion.
Of course, the logical type and character type are not included, and the base data type is ranked as byte<short<int<long<float<double from low to high precision .
an explicit type conversion:
when assigning high-precision variable values to low-precision variables, the display type conversion (also called coercion type conversion) must be used.
Public class test{//Create Class
Public static void Main (string[] args) {//Main method
int number1 = 1; declares an int variable and assigns a value of 1
float number2 = number1; Declares a float variable and assigns a value of number1 the implicit type conversion is used here
int number3 = (int) 12.34; The explicit type conversion is used here and the output value is
         }
}

PS: When converting an integer into a type, you can exceed the range of values to be converted, and you must cast the type. (such as: byte B = (byte) 129; here byte equals-127, for specific reasons, please Baidu understand)


<java Basic > data Type conversion <5>

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.