Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use of underscore in variable and method names

Tags:

People also ask

Is underscore allowed in method name?

Method names should always begin with a lower case character, and should not contain underscores.

Can I use underscore in Java method name?

The rules for Java variable naming are fairly lax. The first letter of a variable must be either a letter, dollar sign or an underscore. After that, any combination of valid Unicode characters or digits is allowed.

Can you use _ in variable names?

Variable names can never contain spaces. The underscore character ( _ ) can also appear in a name.

Should I use underscore in variable names?

Variable names should not start with underscore ( _ ) or dollar sign ( $ ) characters, even though both are allowed. This is in contrast to other coding conventions that state that underscores should be used to prefix all instance variables. Variable names should be short yet meaningful.


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(). Could anybody clarify when to use it?