Primitive Data Structures – Overview

Memory Representation

Representation of boolean, char, Integer in memory

1.png

1

Boolean

  • (1/0) or (true/false) or (+/-) or (Yes/No)
  • used for checking if the given condition passes
  • used in logic checking (AND OR NOT)
  • represented as a binary digit or 1 bit (Java and size not precisely defined)

1

Array: boolean array – boolean[]

1

Byte

  • 8 bit signed two’s complement integer
  • -128 to 127
  • used to save memory for arrays
  • and in some time use in place of int also
  • Array: byte array – byte[]

Character

  • characters are letters, digits, special characters, control characters
  • in java these are 16 bits Unicode characters from ‘\u0000’ to ‘\uffff’
  • represented in ASCII(256 or 2 power 8) or UTF-8 encodings (65535 or 2 power 16)
  • characters together forms a String
  • Array: char array – char[]

1

Note: when you type a character in a notepad and store it will be stored as 1 byte

  • ASCII character -> 1 byte – 8 bit
  • enter /return -> 2 bytes – 16 bit

Floating Point

  • stored in memory as exponents (8 bit) and mantissa (23 bit) and sign bit (1 bit)
  • float – 32 bit
  • double – 64 bit
  • Array: float array – float[]

1.pngInteger

  • short – 16 bit
  • int – 32 bit
  • long – 64 bit
  • Array: char array – int[]

1

Enumerated Types

  • These are fixed length strings

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: