Java Basic data types

Source: Internet
Author: User

The base type has a Boolean, Byte, short, char, int, long, float, double Boolean that evaluates to TRUE or FALSE for the +127~128 concept: the complement of the negative number is the   original code of the absolute value Bitwise negation, and then the entire number is added 1, so the maximum value of byte is 0111 1111, the highest bit is the sign bit (0 for positive, 1 for negative), so the negative value is 1000 0000 (-128 absolute number of the original code to reverse the end plus 1,128 the original code is 1000 0000, the reverse is 011 1 1111, plus 1 is 1000 0000), negative maximum value is 1111 1111 (-1, take reverse plus 1--0000 0001-->1111 1110-->1111 1111). The short value range is: Because the short type occupies 2 bytes in memory, both 16-bit, and the same maximum value is 0111 1111 1111 1111 (2^15 -1),  The minimum value is                  1111 1111 1111 1111 (-2^15).                          ,         &NB Sp                          ,         &NB Sp                     char accounted for 1 bytes with byte,int accounted for 2 bytes 16 bits Byte,short during the conversion process, Char-->int-->long-->float-->double,byte, short and char do not convert to each other, low-level can be advanced conversion, advanced low should pay attention to overflow.   Overflow occurs when double is to float. Experimental generationCode:  public class Testconvert{public static void Main (String []arg) {int i1=123;int i2=456; System.out.println (I1+I2);d ouble d1= (i1+i2) *1.2;//low-->g high RPM, the system automatically converts it to Doule type float f1= ((i1+i2) *1.2);// High-to-low-turn-enhanced conversion character Byte B1=1;byte b2=2;byte b3= (Byte) (B1+B2),///first converted to int, the result is int, need to strengthen the conversion character double d2=1e100; System.out.println (D1+F1+B1+B2+B3+D2); float f2= (float) D2; SYSTEM.OUT.PRINTLN (F2);//will produce overflow float f3=1.23f; SYSTEM.OUT.PRINTLN (F2); long l1=123; System.out.println (L1); long l2=10000000000l; System.out.println (L2);    float f=f1+f2+f3; System.out.println (f); long l= (long) F; System.out.println (l);//system.out.println (f2+f3+l1+l2+f+l);}}   






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.