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
FYI — not tested on the AP CSA Exam
Very small integer.
-128 to 127
Small integer.
-32,768 to 32,767
Standard integer.
Main AP CSA type
Large integer.
Suffix L: 100L
Less precise decimal.
Suffix f: 3.14f
Standard decimal.
Main AP CSA type
True / false.
Main AP CSA type
Single character.
Single quotes: 'A'
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.
What makes a valid variable name?
age ≠ Ageint, class, etc.)studentAge, isActivescore > sMAX_SIZEMyProgramWhich of these are valid?
After the cashier finds the total, the display keeps the answer where everyone can see it.
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.
Variable substitution in expressions
Things work better when they are prepared first and placed where they fit.
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.
Which types can store which results?
Assigning an int result to a double variable works fine — the value is promoted.
Assigning a double result to an int variable causes a compilation error.
"Type mismatch: cannot convert from double to int"
Integer division with mixed types
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)
Understanding the final keyword
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.
Before we start, let's set some ground rules.