Table of Contents
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