Search

Data Type



Data type is used for representing the data in main memory of the computer.
Data types are used for storing the input of the program into the main memory of the computer by allocating sufficient amount of memory space in the main memory of the computer.
In other words data types are used for representing the input of the user in the main memory of the computer.
In general every programming language is containing three categories of data types. They are
(1)     Fundamental / built – in data types
(2)     Derived data types
(3)     User / custom / secondary / programmer defined data types.











Fundamental / built – in data types
Fundamental data types are those whose variables allows us to store only one value but they never allows us to store only one value but they never allows us to store multiple values of same type.
Example:
                Int a;  //  valid
                a = 10,20,30;  //  invalid

Derived data types
Derived data types are those whose variables allows us to store multiple values of same type. But they never allows to store multiple values of different types.
Example:
                Int  a[] = {10,20,30};  // valid
                Int b[] = {100, ‘A’, “ABC”};   //  invalid
In most of the programming languages the concept of arrays comes under derived data types.

User defined data types
User defined data types are those which are developed by programmers by making use of appropriate features of the language.
User defined data types related variables allows us to store multiple values either of same type or different type or both.
Example:
                In C language, user defined data types can be developed by using struct, union, enum etc.
In java programming user defined datatype can be developed by using the features of classes and interfaces.
                Student  s = new  Student();









In above example student is one of the class name in java which is treated as

In java we have eight data type which are organized in four groups. They are
(1)     Integer category data types
(2)     Character category data types
(3)     Float category data types
(4)     Boolean category data types












Integer category data types
This category data type are used for storing integer data in the main memory of computer by allocating sufficient amount of memory space. In other words , this category datatype are used for representing whole numbers in the memory of computer.
Integer category datatype are divided into four types which are given in following table:
S.No
Data type
Size
Range
1
Byte
1
+ 127 to -128
2
Short
2
+ 32767  to -32768
3
Int
4
+ x to – (x+1)
4
Long
8
+ y to – (y+1)



Float category data types
Float category data type are used for representing the data in the form of scale, precision that is these category data type are used for representing float values. This category contains two data types, they are in the given table

S. No
Data type
Size
Range
Number of decimal places
1
Float
4
+2147483647 to -2147483648
8              
2
Double
8
+ 9.223*1018
16





Character category data types
Ø  A  character is an identifier which is enclosed within single quotes.
Ø  In  java to represent character data, we use a data type called char. This data type takes two byte since it follows Unicode character set.









Data Type
Size (Byte)
Range
Char
2
232767 to -32768

Ø  Java is available in 18 international languages and it following Unicode character set.
Ø  Unicode character set is one which contains all the characters which are available in 18 international languages and it contains 65536 character.



Boolean category data types
Boolean category data type is used for representing or storing logical values is true or false.
In java programming to represent Boolean values or logical values, we use a data type called Boolean.
Boolean data type takes zero bytes of main memory space because Boolean data type of java implemented by sun microsystem with a concept of  flip – flop.
A flip – flop is a general purpose register which stores one bit of information (one true and zero false).
Note – in C, C++ (Turbo) Boolean data type is not available for representing true false values but a true value can be treated as non-zero value and false values can be represented by zero

Note – all the keywords in java must starts with small letters.
Define a keyword or reserved word. A keyword is one which will have a special meaning to the compiler of a language.
Example –
                do, while, for, int etc.

In any category contain a more than one data type then to use an appropriate data type from particular category to store a data in the main memory we must know its range

Float category data type
a float data type or  real data is one which is represented in the form of scale, precision.

Eg—
   xxx      yyy
here xxx is called scale, yyy is called precision.
In order to represent float data or real data in the main memory of the computer we use float category data types.
Float category data types are divided into two types and they given in the following table

S. NO
Data type
Size
Range
No. of dec places
1
Float
4
+x to –(x+1)
8
2
Double
8
+y to - (y+1)
16



Range of data type
Range of  any Data type = (A) number of bit occupied by a data type

Where, A = number of bits available in the language which is understand by computer i.e., 2
bits.

Range of byte       = 28
= 1 to 256
= 0 to 255
= 0 to (255/2)
= (127.5 = +127) to (127.5 + 0.5 = -128)