Basic data types in Java byte,short,char,int,long,float,double

Source: Internet
Author: User

Part of the content goes to: Java thoroughly understands the byte char short int float long double

First say byte:

This is an excerpt from the source code in Byte.java in the JDK:

1 /**2 * A constant holding the minimum value a <code>byte</code> can3 * have, -2<sup>7</sup>.4      */5      Public Static Final byteMin_value =-128;6 7     /**8 * A constant holding the maximum value a <code>byte</code> can9 * have, 2<sup>7</sup>-1.Ten      */ One      Public Static Final byteMax_value = 127;

From here you can see the value range of byte: -128---127;

From the point of view of computer composition, it can be explained that byte is 8 bytes in the computer and byte is signed in binary notation when the highest bit is the symbol bit 0 for positive number 1 for negative number.

Maximum value: 127 0111 1111 is 2 of 7 times minus 1;

Minimum: 128 This number once bothered me for a long time, to know that positive numbers in the computer is in the form of the original code, negative numbers in the computer is in its complement form exists, then a negative complement is how to calculate it? is the absolute value of the negative number of the original code to the binary and then the bitwise inversion and add 1,

The following 10 and 10 are examples of: 10 original code: 0000 1010 It's stored in the computer is 0000 1010, so-10? According to the previous calculation except that its absolute value is 10, to the binary 0000 1010 bitwise REVERSE 1111 0101 plus 1:1111 0110, this is-10 complement, OK, the computer 1111 0110 is the representative-10.

Let's take a look at the binary representation of the 128 absolute value 128:1000 0000 Bitwise counter 0111 1111 plus 1:1000 0000, that is 128 in the computer is 1000 0000, and then look at-129 in the computer representation, the absolute value of 129 The range has exceeded the number of bits in byte.

And then you can pass it.

1 // Maximum Value 2 // Minimum Value

Outputs the maximum and minimum values for byte.

In summary, the value range of byte can only be: 128--127-minus 2 of the 7-to-2-7-square minus 1.

The corresponding short as a 16-bit signed shape, int as a 32-bit signed shaping, long as a 64-bit signed shaping can be calculated as above the range of values

Short:

Unicode Character Representations

The char data type (and therefore the value that a Character object encapsulates) is based on the original Unicode Specifica tion, which defined characters as fixed-width 16-bit entities. The Unicode standard have since been changed to allow for characters whose representation requires more than-bits. The range of legal codepoint S was now u+0000 to U+10ffff, known as Unicode scalar value.

Source code in Character.java:

/*** The constant value of this field is the smallest value of type * <CODE>CHAR</CODE> <code> ;‘     /u0000 ' </code>. *     * @since1.0.2*/     Public Static Final CharMin_value = '/u0000 '; /*** The constant value of this field is the largest value of type * <CODE>CHAR</CODE>, <code>     '/uffff ' </code>. *     * @since1.0.2*/     Public Static Final CharMax_value = '/uffff ';

Long:

Float as a 32-bit floating-point type:

Excerpt from Float.java Source:

/*** A constant holding the largest positive finite value of type * <CODE>FLOAT</CODE>, (2-2<sup&     gt;-23</sup>) 2<sup>127</sup>.     * It's equal to the hexadecimal floating-point literal * <code>0x1.fffffeP+127f</code> and also equal to     * <code>float.intbitstofloat (0X7F7FFFFF) </code>. */     Public Static Final floatMax_value = 3.4028235e+38f;//0x1.fffffep+127f    /*** A constant holding the smallest positive nonzero value of type * <CODE>FLOAT</CODE>, 2<SUP&G T;-149</sup>.  It's equal to the * hexadecimal floating-point literal <code>0x0.000002P-126f</code> * and also equal     To <code>float.intbitstofloat (0x1) </code>. */     Public Static Final floatMin_value = 1.4e-45f;//0x0.000002p-126f

Double as 64 for floating-point

Double.java Source:

1 /**2 * A constant holding the largest positive finite value of type3 * <CODE>DOUBLE</CODE>4 * (2-2<sup>-52</sup>) 2<sup>1023</sup>. It's equal to5 * The hexadecimal floating-point literal6 * <code>0x1.fffffffffffffP+1023</code> and also equal to7 * <code>double.longbitstodouble (0X7FEFFFFFFFFFFFFFL) </code>.8      */9      Public Static Final DoubleMax_value = 1.7976931348623157e+308;//0x1.fffffffffffffp+1023Ten  One     /** A * A constant holding the smallest positive nonzero value of type - * <CODE>DOUBLE</CODE>, 2<sup>-1074</sup>. It's equal to the - * Hexadecimal floating-point literal the * <code>0x0.0000000000001P-1022</code> and also equal to - * <code>double.longbitstodouble (0x1l) </code>. -      */ -      Public Static Final DoubleMin_value = 4.9e-324;//0x0.0000000000001p-1022

Basic data types in Java byte,short,char,int,long,float,double

Related Article

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.