Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Variable naming conventions in Java?

Tags:

In PHP, we (at least the good programmers) always start general variable names with a lower-case letter, but class variables/objects with an upper-case letter to distinguish them. In the same way we start general file names with a lower case letter, but files containing Classes with an upper case letter.

E.g:

<?php $number=123; $string="a string"; $colors_array=array('red','blue','red'); $Cat=New Cat(); ?> 

Are the conventions the same in java, i.e Objects starting with upper-case but the rest with lower case, or does everything start with lower case as I've read in other places?

like image 980
Ali Avatar asked Jan 05 '09 18:01

Ali


People also ask

What are variable naming conventions explain?

The choice of a variable name should be mnemonic — that is, designed to indicate to the casual observer the intent of its use. One-character variable names should be avoided except for temporary "throwaway" variables. Common names for temporary variables are i, j, k, m, and n for integers; c, d, and e for characters.

What are the 3 rules for naming a variable?

A variable name must start with a letter or an underscore character (_) A variable name cannot start with a digit. A variable name can only contain alpha-numeric characters and underscores ( a-z, A-Z , 0-9 , and _ ) Variable names are case-sensitive (age, Age and AGE are three different variables)


1 Answers

You can find the naming in the Java Code Conventions.

A quick summary:

  • For classes, use UpperCamelCase.
  • For class members and local variables use lowerCamelCase
  • For packages, use reverse URI, e.g. org.acme.project.subsystem
  • For constants, use ALL_CAPS.
like image 131
jamesh Avatar answered Oct 20 '22 07:10

jamesh