why is it necessary to define data type in Java programming?
Answers
data typing help tells the processor what to expect and the amount of memory space to reserve for what to expect. e.g a variable is declared char or int, this simply tells the computer that reserve so so space for this variable or object so that it can simply hold the value.
Hi
int age;
With the help of data types we can reduce the chances of errors, how?
suppose I have a variable called "age", and we want the "user" to enter his/her age
now we know that age is a number, so we want that user should enter age as 20 not like "20", because we cannot to calculation on "20" but we can on 20, because it is a number but "20" is a string.
if user will enter his/her age like "20" then program will show an error because we have defined our age variable as int.
so with the help of data type we make it redable and can predict the data type of variable even without executing it...
and data type also useful for memory management, how?
honestly i don't know much about it... but i know that "long int" takes almost double space in memory as compared to "int"
btw... in modern programming languages we don't have to mention data types, now a days compilers/interpreters are smart enough to dynamical set data type of a variable.