java object naming conventions code example

Example 1: naming conventions methods java

Methods should be verbs, in mixed case with the first letter lowercase, 
with the first letter of each internal word capitalized.
Example:
run();
runFast();
getBackground();

Example 2: java naming conventions

// Class //
It should start with the uppercase letter.
It should be a noun such as Color, Button, System, Thread, etc.
Use appropriate words, instead of acronyms.
Example:
public class Employee  
{  
//code snippet  
}  

// Interface //
It should start with the uppercase letter.
It should be an adjective such as Runnable, Remote, ActionListener.
Use appropriate words, instead of acronyms.
Example:
interface Printable  
{  
//code snippet  
}  

// Method //
It should start with lowercase letter.
It should be a verb such as main(), print(), println().
If the name contains multiple words, start it with a lowercase letter followed by an uppercase letter such as actionPerformed().
Example:
 class Employee  
{  
//method  
	void draw()  
	{  
//code snippet  
	}  
} 

// Variable //
It should 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 firstName, lastName.
Avoid using one-character variables such as x, y, z.
Example :-
  class Employee  
{  
//variable  
	int id;  
//code snippet  
}

// Package //
It should be a lowercase letter such as java, lang.
If the name contains multiple words, it should be separated by dots (.) such as java.util, java.lang.
Example:
package com.javatpoint; //package  
class Employee  
{  
//code snippet  
}

// Constant //
It should be in uppercase letters such as RED, YELLOW.
If the name contains multiple words, it should be separated by an underscore(_) such as MAX_PRIORITY.
It may contain digits but not as the first letter.
Example:
class Employee  
{  
//constant  
 	static final int MIN_AGE = 18;  
//code snippet  
}

Tags:

Java Example