Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do Java programmers like to name a variable "clazz"? [closed]

People also ask

What does Clazz mean in Java?

Clazz is an abstract class and allows many alternative implementations. Class describes a Java type in terms of fields, methods and constructors. Clazz describes a type in terms of properties, operations and instance factories.

Why naming variables in Java are uppercase and lowercase letters are treated?

The convention is that class names start with an uppercase letter. Variable names are lower camel case. Even if the variable references an object, it still starts with lower case.

What Java naming convention should we used in variables?

For variables, the Java naming convention is to always start with a lowercase letter and then capitalize the first letter of every subsequent word. Variables in Java are not allowed to contain white space, so variables made from compound words are to be written with a lower camel case syntax.


clazz has been used in Java in place of the reserved word "class" since JDK 1.0. "class" is what you want, but abbreviating or inserting junk ("a", "the", "_", etc) reduces clarity. clazz just says class. "International" English speakers (those reading both British and American English) are used to transposing 's' and 'z'.

Since Java has had disclosed source and a suitable culture right from the start, worthwhile Java code and tutorials pick up the same conventions. That's one of the great things about the Java ecosystem, which I think has been an important part of its success.


Because they cannot use the word they want to use which is class. It is reserved.


It's simply because 'class' is a reserved keyword, hence Class class isn't allowed. Therefore you'll see Class clazz or Class cls.


It comes down to the actual compiler and its ability to distinguish what a token means within its context. However, in this particular case, it is the compiler's inability to distinguish what the token class means in a different context. It is a hard and fast rule that class, regardless of its context, is used to denote the declaration of a class, and as such it is a reserved word. That is as simple and as low-level as it gets.

If you feel compelled, you could write your own Java compiler to include a contextual rule that will allow you to use class as a variable name. Though I think it would be far better use of your time to just use clazz or klass -- it would probably be good for your health as well.