Primitive data types

381 views.

The Primitive data types are designed to store a single value and they are used to store the basic inputs required for a program. The primitive types are also called as fundamental data  types.

The Java language provides 8 primitive data types and those are classified into 4 categories

  1. Integer
  2. Floating
  3. Character
  4. Boolean

Integer

This category can used for storing numbers, either positive or negative without a decimal point. Under integer category we have 4 primitive data types and those are

  1. byte
  2. short
  3. int
  4. long

All the 4 primitive data types are used for storing same kind of data, but their sizes and ranges are different so that the memory can be utilized efficiently without any wastage.

Data type Size

 

Range
Byte 1 -128 to 128
Short 2 -32768 to 32767
Int 4 -2147483648 to 2147483647
Long 8 -9223372036854775808 to 9223372036854775807

Floating

This category used for storing numbers either positive or negative with decimal point. Under the floating point category we have two primitive datatypes those are

  1. float
  2. double

Both primitive data types under floating -point category are used for storing same kind of data, but their sizes are different so that memory can be utilized efficiency without waste.

Data type Size

 

Range Number of decimal digits
Float 4 1.4E-45 to 3.4E38 7
Double 8 4.9E-324 to 1.79E308 15

 

Character

This category used for storing a single character. A character can be represented by either one alphabet or one digit or one special symbol. Under the character category there is only one primitive data type and it is Char

Data type Size

 

Range
Char 2 0 to 65535

Boolean

This category used for storing either true or false. Under the Boolean category we have one primitive data type i.e. Boolean.

Data type Size

 

Range
Boolean JVM Dependent True or false

Leave a Reply