HakiDocs
Java

byte

Smallest possible storage unit

Imagine a byte as the smallest possible storage unit 🤏 in the Java warehouse—a tiny locker.

This tiny locker is always exactly 8 bits (or 1 byte) in size.

Because it's so small, it can only hold a very small range of whole numbers: from −128 to +127

Defaults to 0.

We can use this method of How to convert a number to binary to learn the system behind the arrange of bits for each number.

Because byte is smaller than int, it often requires explicit casting when the value is a result of an expression that defaults to int.

byte a = 10; 
byte b = 20; 

byte c = (byte) (a + b); // Explicit type casting

Resources


On this page