Edit Article

Theoretically, you can call the class by any name that is supported by the language itself. However it is better to follow some agreed rules as otherwise other people who view your code may call you and your work "unprofessional" without even looking in how well have you implemented the algorithm. Surprisingly, even students that are about to finish the university does not always name Java classes properly.

Ad

Steps

  1. 1
    The best is to use a single short word that must be a noun ("a name of thing"). Do not use a single verb or single adjective.
    • The selected word should reflect the purpose of the class.
    • If it is not possible to name the purpose of the class clearly with a single noun, add more words using Camel casing (like BorderLayout). Adjectives are best suitable as extra words as they naturally give more information about the noun.
    Ad
  2. Name a Class in Java Step 2.jpg
    2
    Always start the class name with capital letter (this is different from how the variables are named).
  3. Name a Class in Java Step 3.jpg
    3
    Do not use underscore to separate multiple words in a Java class name (it is a rule of C++ programming).
  4. Name a Class in Java Step 4.jpg
    4
    Only use all uppercase names if they directly come from the known abbreviation (URL, UUID and so on).
  5. Name a Class in Java Step 5.jpg
    5
    Always place a class into some package.
    Ad

We could really use your help!

Can you tell us about
motor driven systems?
Yes
No
motor driven systems
how to determine gear ratio in motor driven systems
Can you tell us about
Rome Total War?
Yes
No
Rome Total War
how to unlock factions in Rome Total War
Can you tell us about
breeding rabbits?
Yes
No
breeding rabbits
how to breed rabbits
Can you tell us about
jobs in Hollywood?
Yes
No
jobs in Hollywood
how to get a good job in Hollywood
Thanks for helping! Please tell us everything you know about
...
Tell us everything you know here. Remember, more detail is better.
Tips
Provide Details.
Please be as detailed as possible in your explanation. Don't worry about formatting! We'll take care of it. For example:
Don't say: Eat more fats.
Do say: Add fats with some nutritional value to the foods you already eat. Try olive oil, butter, avocado, and mayonnaise.

Tips

  • Use prefix Abstract (like Abstract Table) to name an abstract class from that you derive something later.
  • Use prefix Default (DefaultLayout) to name a class that is usually default for the given role but can be replaced.
  • Use suffix Factory for the class those primary function is to create instances of another class (like Bubble Factory that produces instances of Bubble).
  • Use suffix Impl for the class that is an implementation of some interface (like BubbleImpl extends Abstract Bubble implements Bubble).
  • Use suffix Exception for exceptions and Error for errors (like All Wrong Exception).
  • Avoid very generic names like Data or Algorithm that do not tell much about the class. Add some suffix or prefix to have it more specific.
  • Better avoid numbers in the class names

Warnings

  • Do not use underscore to name classes, does not matter it is allowed by the language. It is only used when the class closely matches some standard that is officially named with underscores in the name (like in omg.org packages).
  • Consider using English words, not words of your home language. It is a standard language for international cooperation, needed also when it is not a born language for any of the sides
  • For the same reason, do not use national letters outside ASCII data set, even if supported by your environment.
  • Under no circumstances use the dollar sign ($), it is reserved for internal use by compiler.
  • Do not give your class same name as a class in standard library or some other library you use, even if the compiler allows this after you place it into another package. One such mistake in standard API (java.awt.List and java.util.List) has been frequently referred as a problem [1], [2].

Sources and Citations

Article Info

Categories: Java

In other languages:

Español: Cómo nombrar una clase en Java

Thanks to all authors for creating a page that has been read 24,299 times.

Did this article help you?
Yes No

Become
an Author!

Write an Article