Naming Conventions in Java

Naming Conventions in Java


By naming conventions we mean that the rules that should be followed to name the variables, identifiers, classes, constants, etc. These rules are not forced to be followed and therefore, it is called Convention not rule. In java programming language the classes, interfaces, and methods and packages are given according to the naming conventions.


Advantages of Naming Conventions in Java:

When we use naming conventions in Java it becomes easy for us and for the programmers as well to read and modify the code. Readability of program is important for Java and other programming languages as it requires less time period to understand the working and functionality of the code.

Consider the following table:

Name Convention
class name The name of the class should start from an uppercase letter and it should be noun also for example thread, string, etc.
interface name The name of the interface should be started from an upper case letter. The name of interface should be an adjective for example runnable etc.
method name The name of method should be started from a lower case letter and should also be a verb for example main (), print (), etc.
variable name The name of a variable should start from lower case letter for example array, b, etc.
package name The name of the package should be in lower case letter for example java, sql, etc.
constants name The characters in the names of constants should be in upper case RED, etc.


CamelCase in Java naming conventions:

CamelCase syntax for naming a class, method, interface or a variable is supported by Java programming language. If the name is combined with two words then the second word will start with an upper case letter. For example Example Sorting etc.