0% found this document useful (0 votes)
18 views

Java Naming Conventions

Uploaded by

Xee- bii
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Java Naming Conventions

Uploaded by

Xee- bii
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Java Naming conventions

Class
o It should start with the uppercase letter.
o It should be a noun such as Color, Button, System, Thread, etc.
o Use appropriate words, instead of acronyms.
o Example: -

1. public class Employee


2. {
3. //code snippet
4. }

Interface
o It should start with the uppercase letter.
o It should be an adjective such as Runnable, Remote, ActionListener.
o Use appropriate words, instead of acronyms.
o Example: -

1. interface Printable
2. {
3. //code snippet
4. }

Method
o It should start with lowercase letter.
o It should be a verb such as main(), print(), println().
o If the name contains multiple words, start it with a lowercase letter followed by an uppercase letter such
as actionPerformed().
o Example:-

1. class Employee
2. {
3. //method
4. void draw()
5. {
6. //code snippet
7. }
8. }

Variable
o It should start with a lowercase letter such as id, name.
o It should not start with the special characters like & (ampersand), $ (dollar), _ (underscore).
o If the name contains multiple words, start it with the lowercase letter followed by an uppercase letter such
as firstName, lastName.
o Avoid using one-character variables such as x, y, z.
o Example :-

1. class Employee
2. {
3. //variable
4. int id;
5. //code snippet
6. }

Package
o It should be a lowercase letter such as java, lang.
o If the name contains multiple words, it should be separated by dots (.) such as java.util, java.lang.
o Example :-

1. package com.javatpoint; //package


2. class Employee
3. {
4. //code snippet
5. }

Constant
o It should be in uppercase letters such as RED, YELLOW.
o If the name contains multiple words, it should be separated by an underscore(_) such as MAX_PRIORITY.
o It may contain digits but not as the first letter.

1. Example :-
2. class Employee
3. {
4. //constant
5. static final int MIN_AGE = 18;
6. //code snippet }

You might also like