Names allow to identify variables, functions, types, labels and properties of objects. Rules for naming:

  • first character may be letters, underscore _, dollar sign allowed but not recomended
  • subsequent characters may be letters, digits, dollar signs, or underscore characters
  • letters may be ASCII characters a-z, A-Z or unicode characters
  • names are case sensitive, for example x and X are different variables
  • name must not match the reserved word
  • there are naming conventions
String आँtxt = "My text";

naming conventions

identifier type description
package Package name is always written in all-lowercase ASCII letters and should be one of the top-level domain names like com. For example, org.springframework.boot.
Class/interface names should be nouns, in mixed case with the first letter of each internal word capitalized. For example, SpringApplication.
method Methods should be verbs, in mixed case with the first letter lowercase, with the first letter of each internal word capitalized. For example,identityHashCode
variable Variable names are in mixed case with a lowercase first letter. For example, beanNameGenerator.
In android java code style prefix s can be used for static class members, prefix m can be used for class members. For example, sMySingleton or mMyField
Common names for temporary variables are i, j, k, m, and n for integers; c, d, and e for characters.
constant Constants should be all uppercase with words separated by underscores. For example, DEFAULT_REACTIVE_WEB_CONTEXT_CLASS.

reserved words

abstract assert boolean break
byte case catch char
class const continue default
double do else enum
extends false final finally
float for goto if
implements import instanceof int
interface long native new
null package private protected
public return short static
strictfp super switch synchronized
this throw throws transient
true try void volatile