Variables and Datatypes in JAVA
Variable :-
Variables are just a name given to a particular memory location, where it can store the data. Variables are just like label which points to a memory location. This memory location is used to hold the data or store the data.
Examples:-
int num;
char mchar; float denum;
boolean tf_result;Here in the above examples,
num, mchar, denum, tf_result represents the name of the variables. and int, char, float, boolean defines the type of data these respective variables contains.
Any memory location in computer can be accessed by using two things which are given below:
1. Name of the location (Variable Name)
2. Address of the memory location
In former programming to JAVA , like in C and C++ there is use of pointers to access the memory location. Using pointers the data at a particular memory location can be accessed and modified. But the Pointers are complex to implement and understand. Since the data can be accessed directly by using memory address so that is why Pointers breaks the security of data. So because of these two reasons their is no use of pointers in JAVA. In JAVA there is no any concept of pointers. It makes JAVA easy to understand and Secure.
Datatypes in JAVA:-
Datatypes are the keywords used in a programming language which specifies the data to be of a particular type whether the variable contains integer, character, decimal values or set of characters (string).
The Datatypes tells about only two things about the data
1. What kind of Data the variable will store
2. Memory size occupied by the Data to store data in variable
In JAVA, Datatypes are classified into two categories, which are
1. Primitive Datatypes
2. Non - Primitive Datatypes
we can understand this classification by using the below given diagram
Each of these datatypes have different size and default values which are given in the below diagram.
The above diagram can show that there total 8 major datatypes used in JAVA and they can occupy some space in memory. where they can hold the data and this memory location can be accessed easily by using the name of the variable.
The Datatypes tells about only two things about the data
1. What kind of Data the variable will store
1. Primitive Datatypes
2. Non - Primitive Datatypes
we can understand this classification by using the below given diagram
Comments
Post a Comment