How computers remember, organize, and manipulate information in memory.
Can you spot the difference in these gaming stats?
Can you be Level 15.5? Why must this be a whole number?
Wait, 1x damage is normal, but 2x is too much. How do we store that precise 1.5x boost?
Only "Yes" or "No". Do we need a number for this status?
The fundamental building blocks of memory
Stores whole numbers. No decimals!
Example: 1, -5, 100
Stores large decimal numbers.
Example: 3.14, 6.0, -0.5
Stores logic values (true/false).
Example: true, false
Start with the kind, then give each one a name.
Variable = A Named Storage Location
int x;
Setting the Size (Type) & Label (Name).
Naming Tip: Use camelCase (e.g., studentAge)
x = 10;
Placing the very first Content (Value) inside.
Master the direction of data flow
The right side is evaluated first.
The result is stored into the left side variable.
Data always flows from Right ➔ Left.
Using variables for calculation
When a variable appears in an expression, Java uses its current value.
Test your placeholder skills
What is the final value of 'result'?
What happens to the copy?
What is the value of y after all lines execute?
Essential variable safety
Every variable must be assigned a value before it enters an expression.
Values must come from compatible types. No square pegs in round holes!
The power of 'double' in expressions
int only ➔ int
Integer math is strict. Any decimals are deleted!
double involvement ➔ double
If there is at least one double, the result is double.
Integer vs. Double Division
What is the result of the following arithmetic?
Locking the drawer with 'final'
Once a final variable is initialized, its value can never be changed.
Use ALL_UPPERCASE letters for constants.
(e.g., MAX_VALUE, PI)
Final is final
Which line will cause a Compilation Error?
Getting values from the keyboard
import java.util.Scanner;nextInt() for integers,nextDouble() for decimals. Key Takeaways for Variables & Types
Named containers with Type, Name, and Value.
Flows from Right ➔ Left (Calculate first, then store).
Use final to lock values forever.
int / int truncates; double involvement keeps decimals.