Single-Character Variable Name
ID |
java.naming_single_char_var |
Severity |
info |
Remediation Complexity |
trivial |
Remediation Risk |
medium |
Remediation Effort |
low |
Resource |
Naming Convention |
Language |
Java |
Tags |
naming |
Description
Reports fields with single-character names that are not conventional. Conventional names are: i, j, k (int), c (char), b (byte), d (double), f (float), l (long), e (Exception), o (Object).
Rationale
Single-character variable names reduce readability because they carry no semantic meaning. The exceptions above are widely accepted conventions in loop counters and type-specific contexts. Any other single-character field name forces readers to mentally track what x, s, or z represents, increasing cognitive load.
// Bad — non-conventional single-char fields
private int x;
private String s;
// Good — conventional single-char names
private int i;
private char c;
private byte b;
// Good — descriptive names
private int count;
private String name;
Remediation
Replace the single-character name with a descriptive name that conveys the field’s purpose.