Naming conventions in Java language

Naming conventions in java language

In this tutorial, we will dsicuss the concept of Naming conventions in java language

What is the naming conventions in java?

Naming conventions is set of rules to follow as you decide what do you to name your identifier such as Class, Packages, Variable, Constant, methods etc.. ,

When Say in other words,  a set of rules how to named variables, Methods, Class, Packages, Constants that make life of progrmmers easier

Naming convention makes program more easily understandablity and readablity

All names must start with a letter(A to Z or a to z) or an underscore( _ ) or $

Legal names
myname, myName, _special, $MySalary

illegal names
2person, -mysalary, %Duty, @Myname

Never use spaces in the names of things

A space means a new command or a character

legal names
MyName – No space this is legal
This_is_java – No space this is legal

illegal names

My name, This is wrong

Java names may contains

Letter, numbers, Underscore ( _ ) or $ sign

Legal names
Employeedetails10, School_name

Illegal_Names
owner#age,  My@home, best-prize

Naming convention

Package
package name is always written in all lower case letters
java, lang,util

Classes
class name should be noun, in mixed case with the first letter of internal word capitalized – uppercase
eg -Myclass, First, HelloWorld,Patient

Interface
Interface names should be  capitalized looks like class name
Interfaces should be an ajective
eg – Runable, understandable

Methods
Methods should be verb, in mixed case with the first letter lower case and with the first letter of each internal words capitalized
eg – run(), print(), display()

Variables
variable may contain letter and digits drawn from the entire characterset
variable name should start with a lowercase letter. and New word in a name start with the upper case letter
eg .hello, variable, myName, calculate
variables should be self – describing
Variable should be camel case

Contants name
Constants names made up of all uppercase letter with underscores to separate words
eg – PI, MAX_Prize

Karmehavannan

Recent Posts

Multiply two numbers in Java using scanner| 5 different ways

Multiply two numbers in Java using scanner| 5 different ways In this article, we will…

3 months ago

5 different ways to Divide two numbers in Java using scanner

5 Different ways to Divide two numbers in Java using scanner In this article, we…

3 months ago

Learn 8 Ways to Subtract Two Numbers Using Methods in Java

Learn 8 Ways to Subtract Two Numbers Using Methods in Java In this article, we…

4 months ago

10 ways to subtract two numbers in Java

10 ways to subtract two numbers in Java In this article, we will discuss the…

4 months ago

Java Code Examples – Multiply Two Numbers in 5 Easy Ways

Java Code Examples – Multiply Two Numbers in 5 Easy Ways In this article, we…

4 months ago

How to Divide two numbers in Java| 5 different ways

How to Divide two numbers in Java| 5 different ways In this article, we will…

4 months ago

This website uses cookies.