Variables

Declaration:
Syntax:
Datatype variableName;

e.g.
int id;
double salary;
boolean flag;

Initialization:
Syntax:
Datatype variableName;
variableName=value;

e.g.
int id;
id=10;
boolean status;
status=true;

Declaration and Initialization:
Syntax:
Datatype varName=value;

e.g.
double radius=12.5;

Declaration and Initialization multiple variable of same type in one line using comma operator:
Syntax:
Datatype var1=value1, var2=value2, var3=value3,...;

e.g.
int length=100, breadth=200, area=length*breadth;
double radius=100, area=3.14*radius;


Rules for writing name of Variables, Methods and Classes:
  • It consist of alphabets, _(Under Score), $(Dollar) and digits
  • It can only starts-with alphabets, _(Under Score) and $(Dollar)
  • It cannot be Java Keywords
  • It never starts-with digits
  • It does not contains any special symbols except _(Under Score) and $(Dollar)
  • Variables and Methods follows camelCase: It is the practice of writing compound words or phrases such that each word or abbreviation in the middle of the phrase begins with a capital letter
  • Classes follows PascalCase: It is the practice of writing compound words or phrases such that each word or abbreviation of the phrase begins with a capital letter
  • It is case-sensitive

No comments:

Post a Comment