Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is this statement making sense? (Sun's naming convention for Java variables)

I've been quoting this segment from Sun's document for the past few days, and only now do I stop and think about what it's saying, and I can't make any sense of it. Please keep in mind that English is not my first language.

Naming conventions

Variables: Except for variables, all instance, class, and class constants are in mixed case with a lowercase first letter.

How is this making sense? Isn't this saying that class names are in mixed case with a lower-case first letter? Like I should name it class myClass? And class constants are also in mixed case with a lower-case first letter? Like instead of Integer.MAX_VALUE, it should've been named integer.maxValue?

And is it really saying anything about how variables themselves should be named?

Am I not parsing this properly or is this actually a blatant error?

like image 991
polygenelubricants Avatar asked Apr 26 '10 04:04

polygenelubricants


People also ask

What is the naming convention for variables in Java?

Except for variables, all instance, class, and class constants are in mixed case with a lowercase first letter. Internal words start with capital letters. Variable names should not start with underscore _ or dollar sign $ characters, even though both are allowed. Variable names should be short yet meaningful.

What are naming conventions in programming?

In computer programming, a naming convention is a set of rules for choosing the character sequence to be used for identifiers which denote variables, types, functions, and other entities in source code and documentation.

Which option is a valid variable name and follows the Java naming conventions?

Rules to Declare a Variable A variable name can consist of Capital letters A-Z, lowercase letters a-z digits 0-9, and two special characters such as _ underscore and $ dollar sign. The first character must not be a digit. Blank spaces cannot be used in variable names. Java keywords cannot be used as variable names.

How do you define a name in Java?

type variableName = value; Where type is one of Java's types (such as int or String ), and variableName is the name of the variable (such as x or name). The equal sign is used to assign values to the variable.


2 Answers

Sun has accepted this as a bug, with low priority:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4311597

describing the convention for naming variables (the penultimate row in the table). It is plainly wrong - class constants are not in mixed case, as the next row in the table shows. And what is this "except for variables" business? The text is supposed to be describing variables!!

The text should read:

"All instance and class variables are in mixed..."

thus dropping the words "except for variables" and "class constants"

like image 199
Kobi Avatar answered Oct 10 '22 06:10

Kobi


This is a few boxes above it:

Class names should be nouns, in mixed case with the first letter of each internal word capitalized. Try to keep your class names simple and descriptive. Use whole words-avoid acronyms and abbreviations (unless the abbreviation is much more widely used than the long form, such as URL or HTML).

class Raster;
class ImageSprite;

and below that:

The names of variables declared class constants and of ANSI constants should be all uppercase with words separated by underscores ("_"). (ANSI constants should be avoided, for ease of debugging.)

static final int MIN_WIDTH = 4;

static final int MAX_WIDTH = 999;

static final int GET_THE_CPU = 1;

Contradicting, no? "Class constants" should be excluded from that variables convention statement, even if they mean non-static constants of the public final kind, as it confuses people.

As for "except for variables," I believe they mean primitive local variables should only be one word.

like image 41
Brandon Coffman Avatar answered Oct 10 '22 07:10

Brandon Coffman