Last Updated : 30 Jul, 2025
Writing clean, readable and maintainable code is essential, especially in large projects. Naming conventions play a key role by making the purpose of variables, classes, methods and constants clear. This article covers best practices for naming conventions in Java.
Why Naming Conventions are ImportantIn Java, it is good practice to name classes, variables and methods name as what they are supposed to do instead of naming them randomly. Below are some naming conventions of the Java programming language. They must be followed while developing software in Java for good maintenance and readability of code. Java uses CamelCase as a practice for writing names of methods, variables, classes, packages and constants.
Camel's case in Java programming consists of compound words or phrases such that each word or abbreviation begins with a capital letter or first word with a lowercase letter, rest all with capital. Here in simpler terms, it means if there are two
Types of Java Naming ConventionsNote:
- In package, everything is small even while we are combining two or more words in java
- In constants, we do use everything as uppercase and only '_' character is used even if we are combining two or more words in java
In Java, we follow certain rules for naming things like classes, methods, variables and more. These rules make the code more easier to read and understand. One important rule is called CamelCase. This means that when we have a long name made up of several words, we start with a small letter for the first word and use capital letters for the following words.
For example:
myVariableName
This way of naming helps keep the code clean and organized, especially when the project gets bigger.
1. Classes and InterfacesClasses: class Student { }
class Integer {}
class Scanner {}
2. MethodsInterfaces: Runnable
Remote
Serializable
Methods should be verbs, in mixed case with the first letter lowercase and with the first letter of each internal word capitalized.
public static void main(String [] args) {}
Note: As the name suggests the method is supposed to be primarily method which indeed it is as main() method in java is the method from where the program begins its execution.
3. VariablesVariable names should be short yet meaningful.
Variable names should not start with underscore _ or dollar sign $ characters, even though both are allowed.
int[] marks;
double double answer,
Note: As the name suggests one stands for marks while the other for an answer be it of any e do not mind.
4. Constant variables5. Packagesfinal double PI = 3.14159;
double num = PI;
java.util.Scanner ;
java.io.*;
As the name suggests in the first case we are trying to access the Scanner class from the java.util package and in other all classes(* standing for all) input-output classes making it so easy for another programmer to identify.
Note:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4