Variable and Datatype in Java
In this page, we will learn about the variable and java data types.Variable is a name of memory
location. There are three types of variables:local, instance and static. There are two types of
datatype in java, primitive and non-primitive.
Variable 
Variable is name of reserved area allocated in memory.
Types of Variable
There are three types of variables in java
Local Variable
A variable that is declared inside the method is called local variable.
Instance Variable
A variable that is declared inside the class but outside the method is called instance variable .
It is not declared as static.
Static variable
A variable that is declared as static is called static variable. It cannot be local.
We will have detailed learning of these variables in next blog.
Example to understand the types of variables
class A{
int data=50;//instance variable
static int m=100;//static variable
void method(){
int n=90;//local variable
}
}//end of class
Data Types in Java
In java, there are two types of data types
1. primitive data types
2. non-primitive data types
Data Type Default Value Default size
boolean false 1 bit
char '\u0000' 2 byte
byte 0 1 byte
short 0 2 byte
int 0 4 byte
long 0L 8 byte
float 0.0f 4 byte
double 0.0d 8 byte
 
No comments:
Post a Comment