Search code examples
javavariablesnaming-conventions

Use of underscore in variable and method names


I got confused with the (naming convention) use of underscore _ in variable names and method names as their starting letter. For example, _sampleVariable and _getUserContext(). When should I use it?


Solution

  • See the Java Naming Conventions

    Except for variables, all instance, class, and class constants are in mixed case with a lowercase first letter. Internal words start with capital letters. Variable names should not start with underscore _ or dollar sign $ characters, even though both are allowed.

    The names of variables declared class constants and of ANSI constants should be all uppercase with words separated by underscores ("_"). (ANSI constants should be avoided, for ease of debugging.)