Variables and Data Types - Learn Java - Free Interactive Java PDF | US Computer Academy
Variables and Data Types in JavaVariable
Variable is name of reserved
area allocated in memory. its value can be changed
There are
Three types of variables in
java:
Ø
Local
Ø
Instance
Ø
static.
.
1) Local Variable
A variable which is declared
inside the method is called local variable.
2) Instance Variable
A variable which is declared
inside the class but outside the method, is called instance variable . It is
not declared as static.
3) 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 in java
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
Data types represent the
different values to be stored in the variable.
There are
Two types of data types in
java:
Ø
Primitive
Ø
non-primitive.
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
|
Why char uses 2 byte in java and
what is \u0000 ?
It is because java uses Unicode
system than ASCII code system. The \u0000 is the lowest range of Unicode
system. To get detail explanation about Unicode visit next page.
No comments:
Post a Comment
saqlainm329@gmail.com