Java Naming Conventions

Facebooktwitterredditpinterestlinkedinmailby feather

JAVA NAMING CONVENTIONS

Java naming convention is a standard pattern for writing your identifier name such as class, interfaces, methods, constants, variable, etc.

These patterns are not standard rules that you must have to follow, so it is known as the convention, not as rules. These conventions are approved and suggested by several JAVA communities such as Sun Microsystems and Netscape.

All the classes, interfaces, packages, fields, and constants are given according to the naming convention in Java. If you failed to follow these conventions in your code, then it may generate confusion or erroneous code.

Advantage of Java naming convention-

It increases the readability of the code. Readability is one of the important parts of the code, standard pattern makes your code is easy to read for yourself and also for others.

Important points for naming-

  • The name of an identifier must not contain any white spaces.
  • The identifier name should not start with any of special character like *(star), # (hash), $(dollar), & (ampersand) etc.
  • Always choose a meaningful name for the identifier.

Types of cases-

Lowercase-

Lowercase is a case notation where all the words are written in lower format.

e.g.-

Uppercase-

In this case, all the words are written in capitalized format.

e.g.

Camel case-

In this case, each new word is starts with a capital letter.

e.g.

Mixed case-

In this case, the first word starts with a small character after that each new word start with a capital letter. It is the same as camel case notation except the first word.

e.g.

Java Naming Conventions-

Class-

A class name should be in CamelCase. As I told you before, try to use a meaningful name, so class name tries to take as any noun because the class deals with real-world object.

e.g.

Variables-

A variable name should be in mixedCase because variables represent the value of something.

e.g.,

Constants-

Constants name should be taken in UPPERCASE.

e.g.-

Methods-

A method name should be in mixedCase notation. Try to taker verb name because it may describe what the method does.

e.g.

Packages-

The package name should be taken in lowercase. Try to choose a short and meaningful name.

e.g.-

Interfaces-

An interface name should be in CamelCase notation. Its name should be like a class can do.

e.g.-

Facebooktwitterredditpinterestlinkedinmailby feather