Java naming conventions are rules to follow when deciding which name to give to identifiers such as class, package, variable, constant, method, etc.
All classes, interfaces, packages, methods, and fields in the Java programming language should be named following this convention.
Benefits of the Java Naming Convention
Using standard Java naming conventions, the code becomes easier to read for both the author and other developers.
Java Naming Convention Table
Name | Convention |
Class name | It should start with a capital letter and be a noun e.g. String, Color, Button, System, Thread, etc. |
Interface name | It should start with a capital letter and be an adjective e.g. Runnable, Remote, ActionListener, etc. |
Method name | It should start with a lowercase letter and be a verb e.g. actionPerformed (), main (), print (), println (), etc. |
Variable name | It should start with a lowercase letter e.g. firstName, orderNumber, etc. |
Package name | It should be written in small letters e.g. java, lang, sql, util etc. |
The name of the constant | It should be written in capital letters e.g. RED, YELLOW, MAX_PRIORITY, etc. |
CamelCase in Java
Java follows the camelcase syntax for naming classes, interfaces, methods, and variables. If the name is a combination of two words, the second word will always start with a capital letter, e.g., actionPerformed (), firstName, ActionEvent, ActionListener, etc.
To learn more, check out Java tutorials for beginners.