0% found this document useful (0 votes)
10 views1 page

Identifier Naming Rules

Identifiers are names given by programmers to various elements like classes and methods, following specific rules regarding acceptable characters and naming conventions. Class names should start with a capital letter, while method names should be in lowercase or camel case depending on the number of words. Variable names also follow a similar convention, emphasizing the use of lowercase for single words and camel case for multiple words.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views1 page

Identifier Naming Rules

Identifiers are names given by programmers to various elements like classes and methods, following specific rules regarding acceptable characters and naming conventions. Class names should start with a capital letter, while method names should be in lowercase or camel case depending on the number of words. Variable names also follow a similar convention, emphasizing the use of lowercase for single words and camel case for multiple words.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

IDENTIFIERS

Identifiers are the names given by a programmer to a class name, method name, variable

name, and any other member of a class.

Rule for Identifiers

*for identifiers, acceptable characters are A-Z, a-z, 0-9 digits, and special characters only $ and _

*An identifier must not start with the number.

*Space is not allowed for identifiers

*A keyword must not be used as an identifier

Convention for a class name

*if a class name has only one word, then it should be written as the first letter capitalized

and the rest of the letter in lowercase

➔ Program, Demo, Number

*if a class name has multiple words, then the first letter of each word should be capital

➔ ProgramForDataTypes, JavaDemo, NumberProgram

Convention for a method name

*if a method name has one word, then it should be written in lowercase with ().

➔ run(), demo(), number()

*if the method name has multiple words, then the first word should be written in small

letters and from the second word, the first letter of each word should be capitalized with ().

➔ ProgramForDataTypes(), javaDemo(), numberProgram()

Convention for a variable

*if a variable name has one word, then it should be written in small letters.

➔ age, name, id, marks

*if the method name has multiple words, then the first word should be written in small

letters and from the second word, the first letter of each word should be capitalized.

➔ ageOfStudent, nameOfEmployee

Common questions

Powered by AI

Acceptable identifiers include names like myIdentifier1, _hiddenValue, and $tempVar. Unacceptable examples are 1stValue (begins with a number), my Identifier (contains space), and int (a keyword).

Following specific conventions for naming identifiers ensures consistency and readability in the code, which facilitates maintenance and collaboration among developers. Proper naming conventions help avoid confusion and potential conflicts in code interpretation and execution .

Not adhering to the no-space rule in identifiers leads to syntax errors, as programming languages generally interpret spaces as separators between tokens. This results in code that is not compilable, therefore inhibiting execution and rendering the code non-functional .

For one-word variable names, lowercase letters are used, e.g., age. Multiple-word variables begin with a lowercase first word, with each subsequent word's first letter capitalized, e.g., ageOfStudent. This structure improves readability and helps developers identify the nature and scope of variables in the code .

If a class name consists of multiple words, the first letter of each word should be capitalized, exemplified by class names like ProgramForDataTypes, JavaDemo, and NumberProgram .

For identifiers, acceptable characters are the alphabetic characters A-Z and a-z, digits 0-9, and special characters like $ and _. An identifier must not begin with a number and should not contain spaces. Also, a keyword must not be used as an identifier .

A method name with a single word should be written in lowercase followed by parentheses, such as run(). For multiple words, the initial word should be in lowercase, followed by capitalized first letters of subsequent words, such as programForDataTypes(). This distinction enhances clarity and minimizes errors by providing a visually recognizable pattern .

Capitalization is crucial as it distinguishes between aspects of an identifier's function. Class names capitalize the first letter per word; methods use lower camel case; variables use lowercase. This impact aids readability and clarity, facilitating conveying meaning and coding standards .

Prohibiting initial numeric characters in identifiers aligns with syntax rules as numbers typically denote values, not names. Allowing them as prefixes would blur the logical demarcation between variables and literals, causing parser confusion and leading to incorrect analysis or execution paths .

Using keywords as identifiers is prohibited because keywords are reserved words in programming languages that have special meanings or functions. If used as identifiers, they would cause conflicts within the code, leading to errors in interpretation and execution .

You might also like