Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it good practice for Java class names to be plural?

Is it good to have java class name like ExtractionUtils.In naming conventions I no where found anything about plural name of the java class.
I have seen classes like this in one of the project.

like image 684
Jagdev Singh Avatar asked Jul 26 '12 16:07

Jagdev Singh


People also ask

Should class names be singular or plural?

Definitely singular. You don't create an object of People , you create a collection of Person objects. The only time I would use plurals would be for static classes, i.e. SupportServices , StringUtils , etc. However in this case, the class acts more as a namespace than anything else.

What is are the best practice in naming a class in Java?

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).

Should package names be plural Java?

singular just like database table names should always be singular but for different reasons. Look at any popular standard library like Java or Python for example.

Should Java class names have numbers?

Java class names usually begin with a capital letter. Java class names cannot begin with a number. if there are multiple words in the class name like "MyClassName" each word should begin with a capital letter.


2 Answers

Arrays, Collections, Executors, Files, Objects, Utilities [!] - examples from JDK. It kind of violates OO design since all these classes are just namespaces holding utility or factory methods of objects in question while the name suggest they actually contain or maintain a collection of such objects. But being reasonable - I find these names readable and completely fine.

BTW looks like such a naming convention was very popular among Java 7 API designers.

like image 184
Tomasz Nurkiewicz Avatar answered Sep 19 '22 15:09

Tomasz Nurkiewicz


Yes perfectly acceptable to have plurals, look at Collections for example, it is a class which has many static methods which help when dealing with different flavours of collection.

like image 32
Jon Taylor Avatar answered Sep 21 '22 15:09

Jon Taylor