• iconJava Online Training In Andhra Pradesh and Telangana
  • icon9010519704

Opening Hours :7AM to 9PM

Java Variable

Java Variable

Variable :

Variable is an identifier whose value can be changed. or which store the data
Example:
int x=10;
      x=20;


Variable Declaration Rules :
Rule - 1 :

Variable name must be starts with alphabet or underscore or dollar symbol.
Example:
int age=10;
int _age=20;
int $age=30;


Rule - 2 :

The max length of the Variable name is upto 32 characters.


Rule - 3 :

If Variable name contains more than one word ,the second word onwards first letter should be
uppercase letter.
Example:
int studentAge=10;
int studentAgeDetails=10;


Rule - 4 :

No spaces are allowed at the middle of the Variable declaration.
Example:
int student Age=10; (Invalid);


Rule - 5 :

If Variable value contains constant value that Variable name must be
uppercase letter.
Example:
final float PI=3.14;


Rule - 6 :

If constant Variable name contains more than one word ,it should be separated with underscore.
Example:
final float PI_VALUE=3.14;


Rule - 7 :

All keywords are lower case letters.(52 Keywords in java)
Example:
int
float
char


Rule - 8 :

We should not take keyword as a Variable name.
Example:
int if=10;(Invalid)
int If=10;(Valid)



Variable Defination types:
1.Variable Initialization
2.Variable Declaration
3.Variable Assignment

Variable Initialization :

It Means initialize the some value to the Variable.
Example:
int x=10;
      Here 10 is initialize to the x.


Variable Declaration :

In the declaration no value initialize to the Variable.
Example:
int x;


Variable Assignment :

In the assignment assign the value to the Variable or assign Variable to the Variable.
Example:
int x;
      x=10; (It is a value to Variable).

int y;
      y=x; (It is a Variable to Variable).




MSK TechnologiesTrainings


Key Points