Variables and Constants
Published by: Anil K. Panta
Variables
Used to store data values in memory.
Types of Variables:
Class Variables (static) – one copy for all objects.
Instance Variables – different for each object.
Local Variables – exist only within a method or block.
Constants
Value cannot be changed after declaration.
Declared using static final keywords.
Example:
static final double PI = 3.14159;
Data Types in Java
1. Primitive Data Types
byte, short, int, long
float, double
char, boolean
2. Non-Primitive Data Types
String – Sequence of characters (immutable).
Array – Fixed-size collection of elements of the same type.