What is a data type ? What is the use of datatype ?

What is a data type ? What is the use of datatype ?

-A keyword that is used for creating variables and objects for storing single or multiple values is called datatype .

-A variable is a named memory location that is used for storing one value or one object reference .

-An object is also a memory location but it is used for storing multiple values/object .

-A datatype keyword provides below information 

i-Type of the memory

ii-Size of the memory (how many bytes).

iii-type of value and range of  the value .

iv-difference operator allowed to apply 

v-result type comes out from an expression  .

which even the keyword provides above information that keyword is called data type .

For example 

int,long,double,char,boolean ................ keywords are called datatypes .

For example-

if we use the datatypes bytes for creating memory

i-it will create integer type memory .
ii-it will create 1 byte memory .
iii- it allows to store integer value in the range -128 to 127 
iv-if we use byte memory in an expression , it returns result as int type value , but not as byte type value .

For example

byte b1=5; rigght
byte b2=5.0; wrong
byte b3="ab"; wrong
byte b4=true; wrong

Different types of  datatypes

java supports two types of data types

 1-primitive datatypes (8)
2-reference datatype (5)

Primitive data types are used for creating a variable ( one value memory ) for storeing one mathematical value .

reference data types are used for creating an object ( multiple values memory ) for storing multiple values or object of same type or different type ..

Why do we need 8 primitive datatypes and 5 reference datatype ?

based on the type of the values and the range of the values  .

java supports 8 predefined datatype 

The data types int, double , char , and boolean are given based on type of the value 

int for storing integer values

double   for storing floating point values

char for storing character values  

boolean for storing logical values true and false .

The additional datatypes byte short long and float are given based on  range   of the data 

for storing lesser range value we must use byte,short,float .

for storing larger range value we must use long .

Below chart will show you must type and their matching java types --

integer -10,20,30......-int

floating point-10.0,20.0,40.4,50.32...... double

characters 'a'.'b','c','#','1',......-char



Share this

Related Posts

Next Post »