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 datatypes in java, primitive and non-primitive.
Variable
Variable is name of reserved area allocated in memory.
int data=50;//Here data is variable
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 chapters.
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
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
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 datatypes in java, primitive and non-primitive.
Variable
Variable is name of reserved area allocated in memory.
int data=50;//Here data is variable
Types of Variable
There are three types of variables in java
- local variable
- instance variable
- static variable
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 chapters.
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
- primitive data types
- 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
3 comments:
Nice Post! It is really interesting to read from the beginning & I would like to share your blog to my circles, keep your blog as updated.
Regards,
JAVA Training Chennai|JAVA J2EE Training in Chennai
Excellent post!!! In this competitive market, customer relationship management plays a significant role in determining a business success. That too, cloud based CRM product offer more flexibility to business owners to main strong relationship with the consumers.
Best Institute for Cloud Computing in Chennai|Salesforce Training in Chennai|Salesforce Training institutes in Chennai
Great information that you had posted.In-case if anyone wants to learn salesforce training course,can join from our best salesforce training institute.Here we offered world class training with placement support.For more course details,just visit here Microsoft Windows Azure Training | Online Course | Certification in chennai | Microsoft Windows Azure Training | Online Course | Certification in bangalore | Microsoft Windows Azure Training | Online Course | Certification in hyderabad | Microsoft Windows Azure Training | Online Course | Certification in pune
Post a Comment