Today I learned about:
πΉ Instance Variables/ Static Variables
πΉ Difference between Instance and Static Variables
πΉ How memory behaves with static
πΉ Introduction to Operators in Java
This concept helped me understand how data can be shared across all objects in Java π₯
π What is a Static Variable?
A static variable belongs to the class, not to the object.
π It is common for all objects.
π Only one copy is created in memory.
π It is shared across every object of that class.
π§ Instance Variable vs Static Variable
Instance Variable---------- Static Variable
Belongs to object---------- Belongs to class
Separate copy for each object---Single copy shared by all
Created inside heap with object Created once in class memory
π« Example β School Marks Program
Letβs understand using your example.
package java_module_1;
public class School_Vikas {
// Instance variables
int tam_mark;
int eng_mark;
// Static variable
static String School_Name = "Vikas School";
public static void main(String[] args) {
School_Vikas rajiv = new School_Vikas();
rajiv.tam_mark = 60;
rajiv.eng_mark = 50;
System.out.println("Rajiv's Tamil mark is " + rajiv.tam_mark);
System.out.println("Rajiv's English mark is " + rajiv.eng_mark);
// Calling static variable
System.out.println("School Name " + School_Vikas.School_Name);
// We can also call directly inside same class
System.out.println(School_Name);
School_Vikas kumar = new School_Vikas();
kumar.tam_mark = 55;
kumar.eng_mark = 45;
System.out.println("Kumar's Tamil mark is " + kumar.tam_mark);
System.out.println("Kumar's English mark is " + kumar.eng_mark);
}
}
π What Happens Here?
β
Instance Variables
int tam_mark;
int eng_mark;
Each object gets its own copy.
So:
rajiv has separate marks
kumar has separate marks
Memory in Heap:
rajiv β tam_mark = 60
eng_mark = 50
kumar β tam_mark = 55
eng_mark = 45
β
Static Variable
static String School_Name = "Vikas School";
Only ONE copy is created.
Both objects share the same school name.
Memory:
Class Area:
School_Name = "Vikas School"
Even if we create 100 students,
School_Name remains one common value.
π How to Access Static Variable
β Using Class Name (Recommended)
School_Vikas.School_Name
β Directly inside same class
System.out.println(School_Name);
π§ Important Rule
Static variable:
Is created when class is loaded
Does NOT require object creation
Is stored in class memory (Method Area)
π₯ Why Do We Use Static?
We use static when:
β Value is common for all objects
β Data should not change per object
β Utility or shared configuration
Example:
School Name
College Code
Company Name
Interest Rate (bank example)
β Introduction to Operators in Java
An operator is a special symbol used to perform operations.
Example:
- - * / % π Types of Operators 1οΈβ£ Assignment Operator =
Example:
int a = 10;
2οΈβ£ Arithmetic Operators
- - * / %
Example:
int total = 10 + 5;
3οΈβ£ Unary Operators
++ --
Example:
int a = 5;
a++; // Increment
a--; // Decrement
Types:
Post Increment β a++
Pre Increment β ++a
Post Decrement β a--
Pre Decrement β --a
4οΈβ£ Relational Operators
== != < > <= >=
Used for comparison.
5οΈβ£ Conditional Operators
&& ||
&& β AND
|| β OR
π― Key Takeaways β Day 5
β Static variable is shared by all objects
β Instance variable belongs to each object
β Static can be accessed using class name
β Only one copy of static exists in memory
β Operators help perform calculations and comparisons
Date: 24/02/2026
Trainer: Nantha from Payilagam
π€ A Small Note
I used ChatGPT to help me structure and refine this blog.

Top comments (0)