Java Basics (a) the eight basic data types

Since the release of Java basic data type is part of the Java language, namely *** byte, short, int, long, char, float, double, boolean ***.

among them:

Int: byte, short, int, long

Character: char

Float: float, double

Boolean: boolean

Prior to the detailed description, to what science, Java smallest calculation unit *** *** bytes, 1 byte = 8 bits (bit).

A. Integer

In Java integer number of data symbols belong to, i.e. the first bit to 0 indicates a positive integer, the first bit to 1 indicates a negative integer. A negative number is represented by a complement in the computer, then complement how to calculate it?

Complement source negated = + 1;

Such as:

22, in the computer that is 00,010,110,

-22 negated: 11101001, plus 1: 11,101,010

byte

Java byte in the integer part of a length of 1 byte 8bit, value 10000000 (-128) to 01111111 (127), the default value is variable is initialized to 0, Byte packaging

short

the integer part of the Java short length of 2 bytes 16bit, 1,000,000,000,000,000 value (-32768) to 0,111,111,111,111,111 (32767), the default value is variable is initialized to 0, packaging Short

int

the integer part of the Java int length of 4 bytes 32bit, the value -2 ^ 31 (2,147,483,648) to 2 ^ 31-1 (2,147,483,647), the default value is variable is initialized to 0, packaging Integer

long

the integer part of the Java long, 8 bytes in length 64bit, the value -2 ^ 63 (-9,223,372,036,854,775,808) to 2 ^ 63-1 (9,223,372,036,854,775,8087), or the variable is initialized to the default value 0 0L, packaging Long

II. Float

In Java floating-point data can not be directly represented by a binary, but rather a real number for an approximate representation of the data that follows the IEEE 754 standard

float

float part of the Java floating point type, also known as single-precision floating-point, a length of 4 bytes 32bit, variable initialization Default 0.0f, packaging Float

1. float structure

Consists of three parts: a sign bit, the exponent bits, bit mantissa

Sign bit (S) Exponent (E) Mantissa bits (M)
length 1bit 8bit 23bit
Explanation 0 for positive, 1 for negative Format Here Insert Picture Description, E value ranges: (0,255), Here Insert Picture Description:( exponent value Here Insert Picture Description, ) In the form of 1.M or 0.M. Wherein when E = 0, take 1.M, called normal form, when E! = 0, take 0.M, referred to as non-formal

2. float value

Normal form:Here Insert Picture Description

Informal forms:Here Insert Picture Description

Float easily computed according to the above formula in the range of:

Here Insert Picture Description(Minimum, take 1 when the sign bit S, exponent bit taken E 255)

Here Insert Picture Description(The maximum value, set to 0 when the sign bit S, exponent bit taken E 255)

You can take the approximate data therebetween.

Note: Depending on the value of the exponent bit and mantissa bits, there are many special cases, such as NAN, positive infinity, negative infinity, but usually will not use basic, no depth here; at the same time because it is an approximation, so the amount can not be represented indicating the amount recommended BigDecimal

double

double-type part of the Java floating point, double precision floating point is also called a length of 8 bytes 64bit, variable initialization Default 0.0d, packaging Double

1. double structure

Consists of three parts: a sign bit, the exponent bits, bit mantissa

Sign bit (S) Exponent (E) Mantissa bits (M)
length 1bit 11bit 52bit
Explanation 0 for positive, 1 for negative Format Here Insert Picture Description, E value ranges: (0,2047), :( exponent value Here Insert Picture Description, Here Insert Picture Description) In the form of 1.M or 0.M. Wherein when E = 0, take 1.M, called normal form, when E! = 0, take 0.M, referred to as non-formal

2. double value

Normal form:Here Insert Picture Description

Informal forms:Here Insert Picture Description

Easily computed double according to the above formula in the range of:

Here Insert Picture Description(Minimum, take 1 when the sign bit S, exponent bit taken E 2047)

Here Insert Picture Description(The maximum value, set to 0 when the sign bit S, exponent bit taken E 2047)

You can take the approximate data therebetween.

Note: Depending on the value of the exponent bit and mantissa bits, there are many special cases, such as NAN, positive infinity, negative infinity, but usually will not use basic, no depth here; at the same time because it is an approximation, so the amount can not be represented indicating the amount recommended BigDecimal

III. Character

char

char character belonging to the java, 2 bytes 16bit, characters, and can be assigned a single integer value, no default variable initialization, packaging Character.

Such as:

char a = ‘a’;

char a = 'and';

char a = 12; // ranges from 0 to 65536, as char ASCII character encoding type, a corresponding value can be done directly operation, output the corresponding character in the character table

IV. Boolean

boolean

It does not provide a dedicated boolean in the JVM bytecode instructions, and a boolean data after a compiled JVM will be represented by an int, boolean case 4 bytes of data 32, and will be encoded into a boolean array Java virtual machine byte array, in which case each boolean 1 byte of data accounted for 8bit.

-Java virtual machine specification

Only two values, true, false, false variable initialization defaults

Guess you like

Origin blog.csdn.net/fengdongsuixin/article/details/92441027