Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java "User" class naming best practice?

Tags:

java

naming

I'm about to create a User class for my project. Any opinions as to whether it is bad practice to create such a commonly-named class? I could complement it with a prefix specific to my project.

like image 215
Steve Avatar asked Oct 06 '10 04:10

Steve


People also ask

How Should Java classes be named?

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

What is the standard class naming convention in Java?

The standard Java naming convention demands that all reference types be written in PascalCase, also known as upper camel case.

Should Java class names be capitalized?

By convention, Java programs are written entirely in lower case characters with three exceptions. The first letter of class names are capitalized to distinguish class names from member names. The names of constant fields are written entirely capital letters.


2 Answers

This is what packages are for.

like image 150
Ian Henry Avatar answered Oct 12 '22 06:10

Ian Henry


I would suggest you to definitely prefix an application specific term to your User class. "User" is way too common and vague. You might easily end up using API which has "User" class or Interface. Though latest IDEs make it relatively easy to refactor your code, it would be cleaner and easier if you have a app specific "User" class.

like image 31
rkg Avatar answered Oct 12 '22 08:10

rkg