2. NAMING CONVENTIONS
1 | P a g e
Contents
❖ Java Naming conventions .....................................................................................................................2
➢ Advantages of naming conventions in java ..........................................................................................2
1. Class .............................................................................................................................................2
Example: -.................................................................................................................................................2
2. Interface.......................................................................................................................................3
Example: -.................................................................................................................................................3
3. Method .........................................................................................................................................3
Example:-..................................................................................................................................................3
4. Variable........................................................................................................................................4
Example:-..................................................................................................................................................4
5. Package ........................................................................................................................................4
Example:-..................................................................................................................................................4
6. Constant.......................................................................................................................................5
Example:-..................................................................................................................................................5
❖ Camel-Case in java naming conventions..............................................................................................5
3. NAMING CONVENTIONS
2 | P a g e
❖ Java Naming conventions
In java naming convention are rules to follow and define the name of your identifiers such as
(class, package, variable, constant, method, etc.)
In above all the identifiers of Java programming language are given according to the Java
naming convention.
➢Advantages of naming conventions in java
By using Java naming conventions, you make your code easy to readable for yourself and
other programmers. Readability of Java program is very important.
There are following the key rules that must be followed by every identifier:
• The name must start with alphabets.
• The name should not start with special characters like & dollar ($), underscore ( _ )
Now the rules that must be followed by identifiers are as follows:
1.Class
• A class start with the uppercase letter.
• It should be a noun such as Student, Button, System, Thread, etc.
• Use appropriate words, instead of acronyms.
Example: -
1. public class Student
2. {
3. //code
4. }
4. NAMING CONVENTIONS
3 | P a g e
2.Interface
• It should start with the uppercase letter.
• It should be an adjective such as Runnable, Remote, and Action Listener.
• Use appropriate words, instead of acronyms.
Example: -
1. interface Printable
2. {
3. //code
4. }
3.Method
• It should start with lowercase letter.
• In java method are as main(), print(), println().
• If the name contains multiple words, starts it with a lowercase letter followed by an
uppercase letter such as action Performed ().
Example:-
1. class Human
2. {
3. //method
4. void draw()
5. {
6. //code
7. }
8. }
5. NAMING CONVENTIONS
4 | P a g e
4.Variable
• A variable must start with a lowercase letter such as id, name.
• It should not start with the special characters like & (ampersand), $ (dollar), _
(underscore).
• If the name contains multiple words, start it with the lowercase letter followed by an
uppercase letter such as first Name, last-named.
Example:-
1. Class Animal
2. {
3. //variable
4. int id;
5. //code
6. }
5.Package
1. It should be a lowercase letter such as java, Lang.
2. If the name contains multiple words, it should be separated by dots (.) such as
java.util, java. Lang.
Example:-
package javatpoint.com; //package
1. class Employee
2. {
3. //code
4. }
6. NAMING CONVENTIONS
5 | P a g e
6.Constant
• It should be in uppercase letters such as BLUE, GREEN.
• When the name consist of two or more parts than it should be separated by an underscore
( _ ) such as FIRST_NAME.
• First letter not be a letter.
Example:-
1. class Employee
2. {
3. //constant
4. static int MIN_AGE = 21;
5. //code
6. }
❖ Camel-Case in java naming conventions
Java also follows Camel-Case syntax for naming the identifiers. If the name is combination of
two words, the second word will start with uppercase letter always such as First-Name, Second-
Name etc.