Java Naming Conventions
Java has some very straightforward naming conventions. These are universally used by Java programmers, and differ in some cases from conventions commonly used in other languages.
Again, these are conventions. Ignoring them will not prevent your code from running,
as long as you are following Java’s
identifier naming rules are somewhat hard to parse, so a good
rule-of-thumb is that you should use only letters, numbers, and the
_, and they should always start with a letter.
The naming conventions are more like guidelines than rules and are what other Java coders expect to see when reading your code.
|Class||Start with an uppercase letter|
|Method||Start with a lower case letter, and use camelCase to represent multi-word method names|
|Instance variable||Start with a lowercase letter and use camelCase|
|Constant||All uppercase letters, words separated by underscores|
Constants in Java are variables created using both
final modifiers. For example:
static final Double PI = 3.14159
If you’re not sure about all of these identifier types yet, that’s ok. Keep this page in mind for future reference as you read through this book.
Oracle, the company that develops the Java language, provides some more detailed naming conventions . (From the date on this article, you’ll note that these have been relatively standard for a very long time!)