Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java code conventions: Using 'default' as a variable name

I would like to use 'default' as a variable name. Is there a code convention (like class -> clazz) that suggests how I should name the variable?

like image 780
Sand Avatar asked Jun 23 '10 10:06

Sand


2 Answers

I usually add a term that indicates for what it is the default. So I'd use defaultName or defaultPermission or possibly defaultValue (only if the meaning is clear for the context).

like image 129
Joachim Sauer Avatar answered Oct 13 '22 16:10

Joachim Sauer


One more thing: if it is a fixed value - a constant instead of a variable - make it final or even static final/public static final and keep it as class member instead of a local variable. You should write constants upper case.

Example

public class MyClass {

  public static final String DEFAULT_NAME = "MyApplication";

  public String name;

  public MyClass() {
      this.name = DEFAULT_NAME;
  }

}
like image 39
towe75 Avatar answered Oct 13 '22 16:10

towe75