Naming Conventions for final Variables
You'll learn when to use UPPER_CASE vs camelCase for final variables in Java.
Two Different Conventions for Different Purposes
Java has a widely-adopted convention that helps developers instantly recognize what kind of final variable they're looking at:
Constants: UPPER_CASE with Underscores
When a final variable represents a true constant—a value that never changes and is typically defined at the class level—use ALL_UPPERCASE letters with underscores separating words:
final int MAX_USERS = 100;
final double PI_APPROXIMATION = 3.14159;
final char GRADE_A = 'A';
This screaming-snake-case style signals: "This is a fixed, unchanging value used throughout the program."
Local final Variables and Parameters: camelCase
When you use final for local variables or parameters (things you learned in the previous two lessons), stick with normal camelCase naming:
public void processOrder(final int orderId) { // camelCase parameter
final String customerName = "Alice"; // camelCase local variable
final double taxRate = 0.08;
}
These aren't global constants—they're just local values you're preventing from reassignment. Treat them like any other variable naming-wise.
Why the Difference?
Think of it like road signs: STOP signs are in all caps because they're universal, unchanging commands. Street names use normal capitalization because they're contextual. Constants are like STOP signs; local finals are like street names.
Key Takeaway: Use UPPER_CASE for class-level constants, but stick with camelCase for final local variables and parameters—the convention reflects the scope and purpose, not just the final keyword.