Naming Conventions
Summary
Everything starts with a lowercase letter except for class names
(and the .java filename which must match the class name).
You can never use spaces in names of anything in Java.
Use camelCase to name things with more than one word (eg. int enemyHitPoints = 200;
)
Decades ago, people used underscores: int enemy_hit_points = 200;
- Start program with comments to state your name, date, program info, version
number
- Package names: myPackageOfStuff
- Start with lower case
- No spaces
- This also is the name of a folder which all of the classes in the package
must be saved into.
- More info later on URLs and path names
- Class names: MotorizedVehicles
- Start with upper case
- Normally nouns
- No spaces
- Save file with same name: MotorizedVehicles.java
- Methods/Function names: increaseSpeed()
- start with a verb
- start with lowercase
- no spaces
- Other:
- Constants are named in all uppercase: static final int NUM_GEARS = 6;
Indenting
- Always put { on same line as the preceeding statement that began the code block
Some people put each { on its own line; this is okay.
- Put } on separate line always. Make sure that it is aligned properly
- Everything after a { is indented until the matching }
- Exceptions:
- Put { on separate line for class declarations
- Put { on separate line for code blocks which don't have a preceding statement
- I normally write:
} else {
- Need an example ...