Tutorial #1 : Variables And Data Types

Variable is name of memory location, it is an entity that may be change during program execution. There are three types of variables :-

1. Local variable 
2. Instance variable
3. Static variable 

In order to use a variable in a program you to need to perform 2 steps :-
  1. Variable Declaration
  2. Variable Initialization
Examples of other Valid Declarations are :- 

int a,b,c;

float pi;

double d;

char a;

To initialize a variable, you must assign it a valid value.

float pi=3.14f;

double d0=20.22d;

char 'a';

There are three types of variables :-

1. Local variable 
2. Instance variable
3. Static variable 

1.Local Variable :- Variable that is declared inside the method is called local variable.

2.Instance Variable :- Variable that is declared inside the class but outside the method is       Called as instance variable

3.Static variable :- Variable that is declared as static is called static variable.

Example :- 

class A {
    int data = 99; //instance variable  
    static int a = 1; //static variable  
    void method() {
        int b = 90; //local variable  
    }

}

Data Types in Java :- 
  1. Primitive Data Types
  2. Non-primitive Data Types

                Java Data Types
Primitive Data Types
Primitive Data Types are predefined and available within the Java language. Primitive values do not share state with other primitive values.
Data TypeDefault ValueDefault size
byte01 byte
short02 bytes
int04 bytes
long0L8 bytes
float0.0f4 bytes
double0.0d8 bytes
booleanfalse1 bit
char'\u0000'2 bytes

Comments