Variables and Datatypes
Variables and Datatypes
SIZE
PRIMITIVE VALUES
int 0 4 byte
Numbers
long 0l/L 8 byte
Non-Primitive Variable:
• The variable which is used to store a reference.
• It is also known as reference variable
• Syntax: Non primitive datatype identifier1, identifier2
• Example: String s=new String();
Scope of Variable
• The visibility of a variable is known as scope of a
variable.
• Based on scope of variables we can categorize variable
in three types.
1. Local Variables
2. Static Variables
3. Non-Static Variables.(Instance)
Local Variables
Local Variables developed inside a method block or any
other block except class block is known as local
variable.
Characteristics of Local Variable:
• We can’t use local variables without initialization if we
try to use variable without initialization then we get
compile time error.
• Local variable will not be initialized with default values.
• The scope of the local variable is nested inside the
block whenever it is declared, hence it can’t be used
outside the block.