Naming Conventions in java

Naming conventions make programs more understandable by making them easier to read. They can also give information about the function of the identifier-for example, whether it's a constant, package, or class-which can be helpful in understanding the code.

  All the classes, interfaces, packages, methods and fields of java programming language are given according to java naming convention.


Classes

Class names always begin with a capital letter. And if there are multiple words in the class name then each word must also begin with a capital letter.

Class Name should start with uppercase letter and be a noun e.g. Thread,Scanner, FileChooser, ToolKit etc

Example


class MyClassName
{

}

Objects/Variables

Variables must start with lowercase and if there are multiple words in the name, then you need to use Uppercase for starting letters for the words except for the starting word. This is called as CamelCase Convention. for example temp,scannerObject, myVarible etc

Example


String myString;
MyClass myObjec;
int numberOne;
double numberTowForAddition;

Constant Variables:

In Java constant variables are declared using 'static final' modifiers. And such variables must contain only UpperCase charachters and multiple words must be seperated using '_'.

Example


static final int MIN_WIDTH = 4;

static final int MAX_WIDTH = 999;

static final int GET_THE_CPU = 1

Methods:

Method name must start with lowercase and if there are multiple words in the name, then you need to use Uppercase for starting letters for the words except for the starting word.
for example getID() , getName(), getProduct()

Example


void myMethod() 
{

}

Interfaces

Interface names should be capitalized like class names.
for example : MyInterface, Interface,Serializable

Example :


interface MyInter
{

}
woman avatar

What we are going to learn in Declarations