Home >Java >javaTutorial >How many bytes does the java short type occupy?

How many bytes does the java short type occupy?

青灯夜游
青灯夜游Original
2019-12-31 13:56:3920782browse

How many bytes does the java short type occupy?

How many bytes does the java short type occupy?

The short type occupies 2 bytes, 16 bits.

Byte: byte, a unit of measurement used to measure storage capacity, bit (bit).

One byte is equal to 8 bits 1byte = 8bit.

java short type

The short data type is a 16-bit, signed integer expressed in two's complement number

The minimum value is -32768 ( -2^15);

The maximum value is 32767 (2^15 - 1);

Short data type can also save space like byte. A short variable is half the space occupied by an int type variable;

The default value is 0;

Example: short s = 1000, short r = -20000.

Short will be promoted to int type or higher type during operation. This is because Java will automatically treat short data as a literal of type int during the operation. The same is true when performing operations on the byte type, which will be automatically upgraded by Java.

Java integer types

Each integer type in Java has a fixed table number range and field length, which are not affected by the operating system. Ensure the portability of Java programs.

The integer constant in Java language defaults to type int. When declaring long type, you need to add l or L after it, otherwise an error will occur

Type Occupied storage space Number of tables Size
byte 1 word Section -128-127
short 2 Bytes -215~2 15-1
int 4 bytes -231~231-1
long 8 bytes -263~263 -1

Recommended learning: Java video tutorial

The above is the detailed content of How many bytes does the java short type occupy?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn