Chandan D N
Chandan D N

Reputation: 335

what is the significance of placing _ in front of a variable in java?

Can any one tell me what is the significance of placing _ in front of any variable declaration like private String _retForm in java?

Thanks and regards Chandan

Upvotes: 3

Views: 773

Answers (3)

brandizzi
brandizzi

Reputation: 27050

The _ prefix in general means that the field is private (that is, something that other classes should not fiddle with), regardless of the language. It most surely means the same in your example.

Nonetheless, this is not a convention from the "common" Java coding style proposed; in fact, Sun's Java coding style (which used to have a kind of official status, and is still very popular) used to forbid that:

Variable names should not start with underscore _ or dollar sign $ characters, even though both are allowed

Most developers find it annoying and redundant anyway, since Java already specifies when a field is private. Yet others like it.

If you found it in some Java code, this is probably a personal choice of the programmer who wrote it. Some projects (e.g. Liferay Portal) use this code style as well.

Upvotes: 5

singhakash
singhakash

Reputation: 7919

From the Source.

The underscore character; while it's technically legal to begin your variable's name with "_", this practice is discouraged

Upvotes: 0

Ruchira Gayan Ranaweera
Ruchira Gayan Ranaweera

Reputation: 35547

There is no such significance. When you are doing a code there are some best practices which should follow. In Java we are not use _ prefix with variables.

Upvotes: 0

Related Questions