Before we write our first Java program, we shall first start with the definition ofVariables & Keywords and their uses.
What is a Variable?
- A variable is a container which has a size, and a datatype and it is used to hold primitive data or reference to objects. Each variable has a memory location to store its data or value.
- The variables which holds primitive datatype values such as int, long, boolean, short etc.. are called asPrimitive variables. This variable stores the value in its memory location.
- The variables which holds references to the objects is said to be Reference Variables. This variables doesn’t store the object itself in its memory location. It stores the address of the another memory location where the actual value is present.
How to declare and initialize a Variable?
datatype variablename = initialvalue; Examples:
int a =1;boolean b =true;
What is a Datatype?
A datatype is defined as the type of value a variable can hold in it. Primitive and Reference are the two datatypes present in java.
Below are the eight primitive predefined datatypes used in java language named by a reserved keyword.
|Datatype||Size (in bits)||Range|
|byte||8||-128 to 127|
|short||16||-32768 to 32767|
|int||32||-231 to 231-1|
|long||64||-263 to 263-1|
|float||32||1.40129846432481707e-45 to 3.40282346638528860e+38|
|double||64||4.94065645841246544e-324d to 1.79769313486231570e+308d|
|boolean||1||true or false|
|char||16||‘\u0000′(0) to ‘\uffff’(65535)|
These are the datatypes which can be referred to any object or in simple words it is the name of any class named other than the standard Java keywords.
What is a Keyword?
Keyword is a predefined words that are reserved by Java for its own use. Below are the list of keywords used in Java programming language.