Java Basic data types

Source: Internet
Author: User
Java basic data types are numeric (int, byte, short, float, double) char (character char can only represent a single character such as a single letter A or a single character, such as Char c= ' a ' char c= ' I '), Boolean type ( True/false). It is important to note that string strings are a class in Java, not a data type. Decimals in Java are the default type of double. For example, when you want to define a decimal of float, float=2.5 is not compiled in this case, because the default decimal for Java is double,double with a precision higher than float. This is the equivalent of a double high-precision type of data, to a low-precision type processing. So if you want to define the data for float, you need to define that. Float a=2.4f The conversion of the data type, how to convert a high-precision value into a low-precision value. For example, the data of a float type is converted to the data of int: Cast int a = (int) 2.5; When converting high precision to low precision (float-to-int), the data of the fractional part is discarded directly, leaving only the integer part. Conversions in the calculation process the following example is a direct error and cannot be compiled. The reason is that a is a int,3.5 is a double type. This is done by adding an int and a double type of data, and then handing the data type B of an int to the loss of precision that cannot be compiled. When an integer and a high-precision numerical value are calculated, the result of the calculation will go to the high-precision int a=3;int b=a+3.5;

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