Conversion of data types in Java

Source: Internet
Author: User

One: Java data type conversion In addition to Boolean type Boolean (cannot convert) there are two kinds of:< > Automatic conversion; < two > casting

< >, automatic Conversion: The small data type is automatically converted to a large data type. for example, when int and byte are computed, byte ( -128~127) is automatically converted to the type of int ( -2147483648~2147483647).

0.1. Automatic conversion of basic data types:byte->short,char, int, Long Floatdouble, Long RememberSmall Turn big, big turn little will lose precision!!! <1> Conversion of byte:         byte a=120; byte b=a+80; Tip: types converted to byte from int type (80) may lose precision System.out.println (b); <2> Char character conversion Char id= ' a '; a=97 int i=ID+3; System.out.println (i); -    <3> Remember that once the int:int reaches its maximum value, it does not raise its type, but directly loses Precision. int id=2147483647; int g=id+1; System.out.println (g); -2147483648 Why would it be negative -2147483648? the reason is:2147483647 binary is: 0111 1111 1111 1111 1111 1111 1111 1111 if after +1 its binary is: 1000 0000 0000 0000 0000 0000 0000 0000 After conversion to decimal:-2147483648

Conversion of 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.