Tahir heres a story that might help u whats a datatype
All ur family members can make use of all the resources of ur house but ur friend cant DIRECTLY come and start making use of resources he has to take ur permission for that similarly in programming we have datatypes that are used for type saftey we have set of datatypes such as int,float,double,char,string
now if i initialize an integer variable say int x=10;
then in this case variable x will hold only an integer value this is the restriction imposed on x if u try to store string value in x which is an integer type variable u will end up in an error of incompatible type.
Variables are used to store values which are stored in the computers memory, computer memory are very tedious to remember so we declare a human understandable character or word say in this case
int x[where x is an variable which will hold an integer value]
variables can change their values depending upon the code thats called overriding try this code for better understanding
class Example1
{
public static void main(String[ ] args)
{
int x = 10;
System.out.println("value of x before overriding: "+x);
int y =20;
x=x+y;
System.out.println("value of x after overriding: "+x);
}
}
now constants are those variables which do not change their values from start of the program till the end and any attempt to change the value of a constant will throw an error.
In the above story i said ur friend has to take ur permission for using the resources well Tahir sometimes variables have to be typecasted in order to get the desired result u will learn about type casting in the further chapters of ur programming............
Thanks & Regards
Radix :rose:
Do rate my answer once u find it usefull