Thursday, February 18, 2010

Data Type – Lots of hype around it

While we were learning computer programming, having only a few options and always thinking that life as a programmer will be very easy. Thanking all the way to John G. Kemeny and Thomas E. Kurtz from Dartmouth College for their invention, that was the 78KB single file software call BASIC. In our days of learning, we were always thinking all the times about programming only. Apart from BASIC, FORTRAN and PASCAL also there. Then COBOL come calling, cursing it all the time for writing few unnecessary things before finally can start doing what the program meant for. Since then it kept coming to me one after one like big missile C, C++, JAVA, VB, C#, J#. Dot net, HTML with all those script and many DataBase Packages.

In the beginning, we do not have to bother about Data Type, only thinking about Numeric Variable and String variable. Then programming like C enter the scenario and all of certain space and time complexity came to the picture, but frankly speaking no body thought us this very important thing. Anyway, let me explain what Data Type is:

Data Type: A variable is a symbolic name for a computer memory location, while declaring a variable the program must keep track of the type of data or information to be stored in the variable. This is defined as data type.

Primitive data types are those are not composed, it also known as fundamental data types. Each primitive type has - a set of values, a data representation and a set of operations. These are some example of primitive data types:

Integers: Integers are whole numbers with no fractional part. This group includes byte, short, int and long. Where byte keyword is used to declare a primitive Java data type containing an integer value in the range of negative 128 to positive 127. A byte is defined as 8 bits in length, regardless of the platform the Java bytecode executes on.
Characters:: This group includes char data type, store can a solitary letter, digit or symbol.
Floating point: A number with fraction part known as float. This group consists float and double.
Boolean: This group includes Boolean data type, which represents true/false values.
While declaring a variable with particular Data type you have to check with the memory occupation of that Data Type and declare exactly what you want and not something else it may occupy unnecessary memory space. Memory eaten by a Data Type and Range: (also take notice of different type of programming language have its different type space and range)

short : -32768 to 32767, inclusive (2 byte)
int : (for Java and higher ) - +2.15*1009 (4 bytes). (for c and c++) : -32768 to 32767, inclusive (2 byte)
long : 9.22*10308 (8 bytes)
float : + - 3.4*1034 (4 bytes)
double : + - 3.4*10308 (8 bytes)
char : from '\u0000' to '\uffff' inclusive, that is, from 0 to 65535 (2 bytes)
boolean: (2 bytes)

Non primitive types are called reference types and they have name starting with capital letter. Eg: Integer, Float etc. For these primitives you cannot create instances but for the non primitives you can create the instances.

In computer science, composite data types are data types, which can be constructed in a program using its programming language's primitive data types and other composite types. The act of constructing a composite type is known as composition. E.g. struct.

Abstract Data Type: An Abstract Data Type describes values and operations, but not representations. An ADT should protect its data and keep it valid. All, or nearly all, data should be private. Access to data should be via getters and setters. An ADT should provide: A contract, A necessary and sufficient set of operations

Some common ADTs, which have proved useful in a great variety of applications, are : Container, Deque, List, Map, Multimap, Multiset, Priority queue, Queue, Set, Stack, String, Tree.

Each of these ADTs may be defined in many ways and variants, not necessarily equivalent. For example, a stack ADT may or may not have a count operation that tells how many items have been pushed and not yet popped. This choice makes a difference not only for its clients but also for the implementation.

!!!While using Data Type, think about space and time complexity, for time being Sayonara,  next week with bit of programming rules and constant!!

No comments: