Pages

Friday, September 23, 2016

Primitive and Abstract Data Types in Java

Primitive data types are the most basic data types available within the Java language. There are 8 types of primitive data types : boolean, byte, char, short, int, long. float and double.

These primitive types have predefined operations in Java type system and no new operations can be defined on them.

Details of primitive data types are as follows:


CategoryTypesSize (bits)Minimum ValueMaximum ValuePrecisionExample
Integerbyte8-128127From +127 to -128byte b = 65;
char160216-1All Unicode characterschar c = 'A';
char c = 65;
short16-215215-1From +32,767 to -32,768short s = 65;
int32-231231-1From +2,147,483,647 to -2,147,483,648int i = 65;
long64-263263-1From +9,223,372,036,854,775,807 to -9,223,372,036,854,775,808long l = 65L;
Floating-pointfloat322-149(2-2-23)·2127From 3.402,823,5 E+38 to 1.4 E-45float f = 65f;
double642-1074(2-2-52)·21023From 1.797,693,134,862,315,7 E+308 to 4.9 E-324double d = 65.55;
Otherboolean1----false, trueboolean b = true;
void----------

< and > can be used to compare primitive data types. Comparison using these operators cannot be done for abstract data type like string , list, map.

Abstract data types:

The other type of data type is abstract data type. They are called abstract because their implementation is hidden. The combination of data along with its method is called abstract data type.
In general, there are many possible operations that could be defined for each ADT; however, they often fall into these categories:
  1. initialize
  2. add data
  3. access data
  4. remove data
Examples are: List, Stack, Queue, Set, Map, etc.

No comments:

Post a Comment