Careeroza
Naming Rules and Conventions
Rules (must follow)
- Names can contain letters, digits,
_and$. - Names cannot start with a digit:
2ndPlaceis invalid. - Names are case-sensitive:
totalandTotalare different variables. - Reserved words (
int,class,new,public...) cannot be used as names. - No spaces:
first nameis invalid.
Conventions (should follow)
| Kind | Style | Examples |
|---|---|---|
| variables, methods | camelCase | firstName, totalAmount, calculateTax() |
| classes | PascalCase | Student, OrderService |
| constants | UPPER_SNAKE_CASE | MAX_USERS, GST_RATE |
| packages | lowercase | com.careeroza.orders |
Tip: Choose meaningful names. int d = 7; says nothing; int deliveryDays = 7; explains itself.
Practice
Exercise: Which of these names are valid? _count, 2fast, $price, my-name, class, userAge
Show answer
Valid: _count, $price, userAge
Invalid: 2fast (starts with a digit)
my-name (hyphen not allowed)
class (reserved keyword)