Monday, September 23, 2013

What are the Primitive Data Types?

There are eight primitive data types in Java. They are:
  1. boolean: This supports only two values true and false. This type is used for true/false conditions.
  2. byte: Represents 8 bit integer. It is useful while handling large arrays of numbers, as the memory usage is minimal.
  3. short: Represents 16 bit integer.
  4. int: Represents 32 bit integer.
  5. long: Represents 64 bit integer.
  6. float: Represents 32 bit single precision floating point.
  7. double: Represents 64 bit double precision floating point
  8. char: Represents a single Unicode character. Its size is 16 bits.
Data TypeDefault Value (for fields)Size (bits)Range
booleanfalseNot definedtrue/false
byte08-128 to 127
short016-32,768 to 32,767
int032-2,147,483,648 to 2,147,483,647 
long0L64-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
float0.0f32Details coming up in a separate post.
double0.0d64Details coming up in a separate post.
char'\u0000'16'\u0000' to '\uffff'
Of these types, char and boolean are not numeric. The rest are numeric in nature.

Primitive data types are not dependent on any external libraries for usage. This is because they are built into the language itself.


No comments:

Post a Comment