How to Name a Class in Java

The best is to use a single short word that must be a noun ("a name of thing")., Always start the class name with capital letter (this is different from how the variables are named). , Do not use underscore to separate multiple words in a Java class...

6 Steps 1 min read Medium

Step-by-Step Guide

  1. Step 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.
  2. Step 2: Always start the class name with capital letter (this is different from how the variables are named).

    ,,,
  3. Step 3: Do not use underscore to separate multiple words in a Java class name (it is a rule of C++ programming).

  4. Step 4: Only use all uppercase names if they directly come from the known abbreviation (URL

  5. Step 5: UUID and so on).

  6. Step 6: Always place a class into some package.

Detailed Guide

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.

,,,

About the Author

D

Diane Campbell

Dedicated to helping readers learn new skills in practical skills and beyond.

68 articles
View all articles

Rate This Guide

--
Loading...
5
0
4
0
3
0
2
0
1
0

How helpful was this guide? Click to rate: