DEV Community

Cover image for Identifiers in Kotlin
Jay Tillu😎
Jay Tillu😎

Posted on

Identifiers in Kotlin

  • Identifiers are the name given to objects, variables, classes, and functions, etc. For example: var age = 45

  • Here var is a keyword and age is the name given to variable.

Rules for naming identifiers

There are five rules which are applied to naming identifiers.

  • Identifiers can contain letters, underscore, and digits. But must not start with a digit.
var 1userBalance = 2500  // Identifier cannot start with numbers.
var $dollar = 60  // Identifiers cannot contain special symbols.
  • Whitespaces are not allowed.
var High Score  // Identifiers cannot contain whitespaces.
  • Special symbols are not allowed except underscore.
($, #, ?, <>, ~, ! Not allowed)
  • Identifiers are case sensitive.
var HighScore or highScore // both highscores are different here.
  • In kotlin, a hard keyword cannot be used as identifiers.
var class  // hard keywords cannot be used as identifiers.
  • When creating variables, classes, objects or functions, choose a name that makes sense. For example score, number, levels, userData makes more sense then variable name such as a, b, c. Although they are valid.

Camel Casing

  • Camel casing is a naming pattern, mostly used in naming programming.

  • There are two types of camel casing:

  • Upper camel case

  • Lower camel case

  • Use camel casing naming method is always recommended in programming.

  • Upper camel case — In upper camel case, the first letter of the new word is upper case, allowing it to be easily distinguished from a lower case.

var HighScore = 250   //Example of upper camel case.
  • Lower camel case — In Lower camel case, the first letter of the first name is the lower case then after every new word will be upper case, allowing it to easily distinguished from an upper case.
var highScore = 250   //Example of lower camel case.

What is WhiteSpaces?

  • In computer programming, white space is any character or series of character that represents horizontal or vertical space in typography.
var high Score = 250   //Compile time error. Whitespace not allowed.
  • Space bar, tab and enter button mostly used to insert whitespaces.

  • Remember most of the compilers don’t allow whitespaces. So avoid them as much as possible in your programs.

Wanna get in touch with me? Here are links. I’ll love to become your friend. 😊
or just mail me at

Discussion (0)