«Back to Home

Core Java

Topics

Naming Conventions In Java

Naming Convention

A naming convention is an instruction to follow, as you decide what to name your identifiers. For example, class, package, variable, method etc.
 
Why we use Naming Conventions in Java?

Different programmers can have different techniques to design a program. With the help of standard Java naming conventions, they make their code easy to use, read for themselves and for other programmers. In Java, readability is important because it takes less time to solve errors the and what the code does. With the help of it, we can easily modify the code and check the code. It’s very beneficial to the programmers. A programmer with the help of these rules will be able to understand the code written by other programmer.
 
Naming Conventions
  • class name

    Class name must be as a noun and starts with the uppercase letter. For example- Employee, Shapes, Bike, System, etc.

  • interface name

    Interface name must be an adjective and starts with the uppercase letter. For example- Runnable, Remote, ActionListener etc.

  • method name

    Method name must be a verb and starts with the lowercase letter. For example- message(), main(), print(), println() etc.

  • variable name

    Variable name must start with the lowercase letter. For example- firstName, orderNumber etc.

  • package name

    Package name must start in lowercase letter. For example- java, io, lang, sql, util etc.

  • constants name

    Constant name must be in uppercase letter. For example- PINK, CIRCLE, MIN_PRIORITY etc.
Other cases in Java
  • CamelCase

    CamelCase is also called as Upper CamelCase. In this, every word starts with a capital letter. For example- SavingAccount, PlayingCard etc.

  • Mixed case

    Mixed case is also called as Lower CamelCase. In this, the first letter of the name is lowercase. For example- emplyeeFirstName, employeeLastName etc.
Summary

Thus, we learnt naming convention is an instruction to follow, as you decide how to name your identifiers and also learnt other cases in Java.