I have a question about how to name a class in java. Could a class name be arbitrary or have to obey some rules? For example, I want to define linked lists in a class, does the class name have to be "ListNode" in order to ensure it is a recursive data type?

  • 1
    The name of a class has nothing to do with whether it's "recursive" or not, and it wouldn't make any sense if it did. The only rule I'm aware of is that a class' name has to be a valid identifier, which shouldn't be surprising. – Ixrec Mar 29 '16 at 12:25
  • 1
    Naming is a difficult problem in software engineering. There is no one "right" way to name objects or classes (though there are definitely wrong ways to do it). Best thing to do is use a coding and naming standard, that best fits your practices (and follow it consistently). You can use an existing one or define your own. My advice would be to use Google Java Style guide. For most elements a name will not ensure that it will be a particular type or enforce the way it is used. – Miguel van de Laar Mar 29 '16 at 12:26

The compiler does not understand English. To the compiler, ListNode, LijstElement and Bla1234567 are equally good names for a class that represents an element in a linked list.

When naming your classes (and functions, methods and variables), you should mostly consider your fellow humans that have to read the code (including yourself in a few months). They will have to be able to understand that the name stands for with the least amount of effort.


There are no compulsory rules with naming in java, however there are few conventions you should follow in java : http://www.iwombat.com/standards/JavaStyleGuide.html#Class%20and%20Interface%20Names

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.