The Java + Spring Boot Blueprint (Blog 4: Variables in Java — How Your Program Stores Data)
Variables in Java Explained for Beginners | How Java Stores Data (Java + Spring Boot Series Blog 4)
The Java + Spring Boot Blueprint (BLOG 4 — Variables in Java (What They REALLY Are)

Before data types, you must understand variables.
In Blog 3, we understood how Java programs are structured and how execution starts.
Now the next question is:
Where does your program store data?
The answer is:
Variables
What is a Variable (Simple Truth)
A variable is NOT a box.
👉 It’s a label pointing to a memory location.
Visual Understanding
int x = 10;
Stack Memory:
[x → 10]
👉 x is just a name 👉 10 is stored in memory
Common Mistake
“Variable stores value”
👉 Correct:
Variable refers to a location where value is stored
How to Declare a Variable
In Java, every variable must have a type.
Syntax:
dataType variableName = value;
Example:
int age = 25;
double salary = 50000.50;
char grade = 'A';
Why Do We Need a Data Type?
Java needs to know:
- What kind of value are you storing
- How much memory to allocate
- What operations are allowed
This is why Java is called:
A statically typed language
What Does “Statically Typed” Mean?
It means:
You must define the type of variable at compile time.
Example:
int age = 25;
age = "Hello"; // Error
Java will not allow changing the type later.
This makes Java:
- Safer
- More predictable
- Less error-prone
Variable Naming Rules
Rules:
- Must start with a letter,
$, or_ - Cannot start with a number
- Cannot use keywords (like
int,class) - Case-sensitive (
ageandAgeare different)
Naming Conventions (Best Practice)
Follow camelCase:
int userAge;
double accountBalance;
Good names improve readability.
Types of Variables (Basic Understanding)
Java has mainly 3 types:
1. Local Variables
Declared inside methods.
void test() {
int x = 10;
}
2. Instance Variables
Declared inside class but outside methods.
class User {
int age;
}
3. Static Variables
Shared across all objects, we will learn this in detail in the coming blogs.
class User {
static int count = 0;
}
Important Concept: Reference Variables (Intro)
Some variables don’t store actual data.
They store the reference (address).
Example:
String name = "Ram";
name→ reference"Ram"→ actual data
We will understand this deeper in the coming days.
Why This Matters
This concept is the foundation of:
- Memory (Stack vs Heap)
- References
- Objects
Common Beginner Mistakes
- Not declaring type
- Using wrong variable names
- Confusing
=with comparison - Not understanding static typing
Interview Questions
- What is a variable?
- What is static typing?
- Types of variables in Java?
- Difference between a local and an instance variable?
Next (Blog 5)
Now that you understand variables,
We will move to:
Data Types in Java Primitive vs Non-Primitive Default values Reference vs value
This will make your understanding much stronger.
메타데이터
- post_id
- d79b8cd60546
- slug
- the-java-spring-boot-blueprint-blog-4-variables-in-java-how-your-program-stores-data-d79b8cd60546
- url
- https://medium.com/codetodeploy/the-java-spring-boot-blueprint-blog-4-variables-in-java-how-your-program-stores-data-d79b8cd60546
- canonical_url
- https://medium.com/codetodeploy/the-java-spring-boot-blueprint-blog-4-variables-in-java-how-your-program-stores-data-d79b8cd60546
- author_url
- https://medium.com/@theDevBluePrint
- status
- ok
- fetched_at
- 2026-06-28 10:39:35