Skip to content

saitolearn/-Java-Primitive-Data-Types-Memory-Representation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

4 Commits
ย 
ย 

Repository files navigation

๐Ÿง  Java Primitive Data Types โ€“ Memory Representation

This guide explains how Java primitive data types are stored in memory using simple examples, binary formats, and visual aids.

๐Ÿ”น 1. byte a = 10;

byte a = 10; Variable Type Size Decimal Binary a byte 1 B 10 00001010

Visual: +--------+ |00001010| +--------+

๐Ÿ”น 2. short b = 300; short b = 300; Variable Type Size Decimal Binary b short 2 B 300 00000001 00101100

Visual: +--------+--------+ |00000001|00101100| +--------+--------+

๐Ÿ”น 3. int c = 1000;

int c = 1000; Variable Type Size Decimal Binary c int 4 B 1000 00000000 00000000 00000011 11101000

Visual: +--------+--------+--------+--------+ |00000000|00000000|00000011|11101000| +--------+--------+--------+--------+

๐Ÿ”น 4. long d = 100000L; long d = 100000L; Variable Type Size Decimal Binary (simplified) d long 8 B 100000 Ends with 00011000011010100000

Visual (simplified): +--------+--------+...+--------+ |00000000...00011000011010100000| +--------+--------+...+--------+

๐Ÿ”น 5. char e = 'A'; char e = 'A'; Variable Type Size Char Unicode Binary e char 2 B 'A' 65 00000000 01000001

Visual: +--------+--------+ |00000000|01000001| +--------+--------+

๐Ÿ”น 6. float f = 3.14f; float f = 3.14f; Variable Type Size Value Binary (approx) f float 4 B 3.14 01000000 01001000 11110110 11000010

Visual: +--------+--------+--------+--------+ |01000000|01001000|11110110|11000010| +--------+--------+--------+--------+

๐Ÿ”น 7. double g = 3.14; double g = 3.14; Variable Type Size Value Binary (approx) g double 8 B 3.14 01000000 00001001 00111111 ...

Visual: +--------+--------+--------+--------+--------+--------+--------+--------+ |01000000|00001001|00111111|11011011|00110000|00000000|00000000|00000000| +--------+--------+--------+--------+--------+--------+--------+--------+

๐Ÿ”น 8. boolean h = true; boolean h = true; Variable Type Size Value Binary h boolean 1 B true 00000001

Visual: +--------+ |00000001| +--------+

๐Ÿงฉ Summary Table

Type Size Example Value Binary Bits (approx)
byte 1 byte 10 00001010
short 2 bytes 300 00000001 00101100
int 4 bytes 1000 00000000 00000000 00000011 11101000
long 8 bytes 100000 (Long binary)
char 2 bytes 'A' 00000000 01000001
float 4 bytes 3.14f 01000000 01001000 ...
double 8 bytes 3.14 01000000 00001001 ...
boolean 1 byte true 00000001

๐Ÿ“Œ Note: Floating point binary values follow IEEE 754 format and are approximated here for simplicity.

About

๐Ÿง  Java Primitive Data Types โ€“ Memory Representation - Explained

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published