What are Variables, Constants, Identifiers & Data Types (in JAVA) ?
Today i am going to discuss about Variables and Constants here w.r.t JAVA. Please note that the definition of Variables and Constants is same for all languages so, what ever i tell here is not just limited to JAVA i.e you can apply it in any language only syntax will change.
Let me start with Variables.
What are Variables ?
It is a name given to a memory location where value can be out. A variable can hold only a single value at a time.
Value of a variable can change during execution of the program.
What are Constants ?
Its value never changes during execution of the program.
to define a constant final keyword is used
final int A = a;
NOTE: A is a constant and it must be uppercase.
What are Identifiers ?
It is a name given to a variable or constant or method or class.
Rules for Identifiers :-
- It can be a combination of alphabets (a-z, A-Z) or digits (0-9) and a special character ‘_’.
- Identifier name can begin with either alphabets of underscore only.
- space should not be given in identifier.
|a b c||wrong|
What are Data Types ?
It specifies the type of data to be stored in a variable.
Data Types can be Predefined (or Library or Primitive) and User defined