Java Naming Conventions - Javatpoint https://www.javatpoint.
com/java-naming-conventions
Home Java Programs OOPs String Exception Multithreading
1 of 7 21/09/2023, 11:53
Java Naming Conventions - Javatpoint https://www.javatpoint.com/java-naming-conventions
Java Naming Convention
Java naming convention is a rule to follow as you decide what to name your identifiers such as class,
package, variable, constant, method, etc.
But, it is not forced to follow. So, it is known as convention not rule. These conventions are suggested by
several Java communities such as Sun Microsystems and Netscape.
All the classes, interfaces, packages, methods and fields of Java programming language are given according
to the Java naming convention. If you fail to follow these conventions, it may generate confusion or
erroneous code.
Advantage of Naming Conventions in Java
By using standard Java naming conventions, you make your code easier to read for yourself and other
programmers. Readability of Java program is very important. It indicates that less time is spent to figure out
what the code does.
Naming Conventions of the Different Identifiers
The following table shows the popular conventions used for the different identifiers.
Identifiers Naming Rules Examples
Type
2 of 7 21/09/2023, 11:53
Java Naming Conventions - Javatpoint https://www.javatpoint.com/java-naming-conventions
Class It should start with the uppercase letter. public class
It should be a noun such as Color, Button, System, Thread, etc. Employee
Use appropriate words, instead of acronyms. {
//code snippet
}
Interface It should start with the uppercase letter. interface Printable
It should be an adjective such as Runnable, Remote, {
ActionListener. //code snippet
Use appropriate words, instead of acronyms. }
Method It should start with lowercase letter. class Employee
It should be a verb such as main(), print(), println(). {
If the name contains multiple words, start it with a lowercase // method
letter followed by an uppercase letter such as actionPerformed(). void draw()
{
//code snippet
}
}
Variable It should start with a lowercase letter such as id, name. class Employee
It should not start with the special characters like & (ampersand), {
$ (dollar), _ (underscore). // variable
If the name contains multiple words, start it with the lowercase int id;
letter followed by an uppercase letter such as firstName, //code snippet
lastName. }
Avoid using one-character variables such as x, y, z.
Package It should be a lowercase letter such as java, lang. //package
If the name contains multiple words, it should be separated by package
dots (.) such as java.util, java.lang. com.javatpoint;
class Employee
{
//code snippet
}
Constant It should be in uppercase letters such as RED, YELLOW. class Employee
If the name contains multiple words, it should be separated by an {
underscore(_) such as MAX_PRIORITY. //constant
It may contain digits but not as the first letter. static final int
MIN_AGE = 18;
//code snippet
}
CamelCase in Java naming conventions
3 of 7 21/09/2023, 11:53
Java Naming Conventions - Javatpoint https://www.javatpoint.com/java-naming-conventions
Java follows camel-case syntax for naming the class, interface, method, and variable.
If the name is combined with two words, the second word will start with uppercase letter always such as
actionPerformed(), firstName, ActionEvent, ActionListener, etc.
← Prev Next →
Youtube For Videos Join Our Youtube Channel: Join Now
Feedback
◦ Send your Feedback to feedback@javatpoint.com
Help Others, Please Share
4 of 7 21/09/2023, 11:53
Java Naming Conventions - Javatpoint https://www.javatpoint.com/java-naming-conventions
Learn Latest Tutorials
Splunk SPSS tutorial Swagger T-SQL tutorial Tumblr
tutorial SPSS tutorial Transact-SQL tutorial
Splunk Swagger Tumblr
React tutorial Regex tutorial Reinforcement R RxJS tutorial
ReactJS Regex learning Programming RxJS
tutorial tutorial
Reinforcement R Programming
Learning
React Native Python Design Python Pillow Python Turtle Keras tutorial
tutorial Patterns tutorial tutorial Keras
React Native Python Design Python Pillow Python Turtle
Patterns
Preparation
Aptitude Logical Verbal Ability Interview Company
Aptitude Reasoning Verbal Ability Questions Interview
Reasoning Interview Questions
Questions Company
Questions
Trending Technologies
Artificial AWS Tutorial Selenium Cloud Hadoop
Intelligence AWS tutorial Computing tutorial
Artificial Selenium Cloud Hadoop
Intelligence Computing
ReactJS Data Science Angular 7 Blockchain Git Tutorial
Tutorial Tutorial Tutorial Tutorial Git
ReactJS Data Science Angular 7 Blockchain
Machine DevOps
Learning Tutorial
Tutorial DevOps
Machine
Learning
5 of 7 21/09/2023, 11:53
Java Naming Conventions - Javatpoint https://www.javatpoint.com/java-naming-conventions
B.Tech / MCA
DBMS tutorial Data DAA tutorial Operating Computer
DBMS Structures DAA System Network
tutorial Operating tutorial
Data Structures System Computer
Network
Compiler Computer Discrete Ethical Computer
Design Organization Mathematics Hacking Graphics
tutorial and Tutorial Ethical Hacking Tutorial
Compiler Architecture Discrete Computer
Design Computer Mathematics Graphics
Organization
Software html tutorial Cyber Automata C Language
Engineering Web Technology Security Tutorial tutorial
Software tutorial Automata C Programming
Engineering Cyber Security
C++ tutorial Java tutorial .Net Python List of
C++ Java Framework tutorial Programs
tutorial Python Programs
.Net
Control Data Mining Data
Systems Tutorial Warehouse
tutorial Data Mining Tutorial
Control System Data
Warehouse
6 of 7 21/09/2023, 11:53
Java Naming Conventions - Javatpoint https://www.javatpoint.com/java-naming-conventions
7 of 7 21/09/2023, 11:53