What is the value range of the java data type

  • 2020-05-27 05:38:53
  • OfStack

java data type:

In Java, there are two main types of data: basic data types (value types) and wrapper types (reference data types). The base data type is not an object and cannot call toString (), hashCode (), getClass (), equals (), and so on.

8 basic data types --8 packaging types


  byte   Byte  【  -128 . 127 】  1 Bytes ([] -2 the 7 The power, 2 the 7 To the power -1 )   1 Bytes are 8 position     

  short  Short      【 -32768 . 32767 】  2 Bytes ([] -2 the 15 The power, 2 the 15 To the power -1 )  2*8-1

  int   Integer     【 -2147483648 . 2147483647 】  4 Bytes ([] -2 the 31 The power, 2 the 31 To the power -1 ) 4*8-1

  long   Long   【 -9223372036854774808 . 9223372036854774807 】  8 bytes   ( 【  -2 the 63 The power, 2 the 63 To the power -1 )  8*8-1

It can be seen that the value range of byte and short is relatively small, while the value range of long is too large and takes up too much space. Basically, int can meet our daily calculation, and int is also the most used integer type.

Under normal circumstances, if the JAVA appeared one integer number 35, for example, then this number is int type, if we want it to be byte model, can add a uppercase B after data: 35 B, said byte type, it is the same type of 35 S said short, 35 L said long model, said int we can what all need not add, but if you want to say long type, 1 set to add "L" behind the data.

Floating point:

float Float 4 bytes

double Double 8 bytes

The difference between them is their accuracy

Type double has a larger storage range and higher accuracy than type float, so floating point data is usually of type double without being declared. If you want to indicate that a data is of type float, you can add "F" to the data.

Floating point data can't be completely accurate, so it's normal to see a float at the end of the decimal point during calculations.


charCharacter 2 bytes

The data type used for storing characters, occupying 2 bytes, adopts unicode encoding, and its first 128 byte encoding is compatible with ASCII

The storage range of characters is from \u0000 to \uFFFF. Be careful to add ' 'when defining character type data, for example '1' means character '1' instead of value 1

Boolean type:

boolean Boolean

There are only two values, true and false

Thank you for reading, I hope to help you, thank you for your support of this site!

Related articles: