Home java Correct Java class names

Correct Java class names

Author

Date

Category

Hello everyone.
I suffer from the inability to correctly name my classes. Colleagues also suffer from this =)

Here is some collection of rules for how to name the correct class. It is clear that he should reveal the essence of the class’s work, but how I understand his work may differ from how his colleague understands his work. This partly says that the class itself is not correctly designed, but nevertheless.

For example, I have a class that I need in order to generate an html page, and place it in the jboss temp directory so that the REST method returns a link to this page.

Actually, I named the class buildingList.class
Everything works fine, but I can’t think of a name for a pancake.


Answer 1, authority 100%

Well, they seem to have written everything correctly, nevertheless the element of understatement remained – I hasten to fill the gap (following the traces of the document Java Naming Convention and my experience):

  1. Class names: start with a capital letter and must be nouns like
    BuildingList in CamelCase
  2. style

  3. Interface names: start with a capital letter and must be an adjective, such as:
    Buildable – also in CamelCase
  4. style

  5. Method names: start with a lowercase letter and must be verbs (style
    CamelCase ), type: buildList
  6. Variable names: start with a small letter, like: myList – in the style of CamelCase
  7. Package names: all in small letters, like: com.builder.list – not in style
    CamelCase , it is customary to name packages with the owner’s domain name, such as: ru.padawan.builder.list , it is considered good practice to register your domain name and actively use your domain name with package names.
  8. Constant names: all capitalized, like: MY_LIST_CONSTANT CamelCase style is not
    applies, words are separated by underscores.

CamelCase (literally camel case ) is when each new word is capitalized, such as: HereIsCamelCaseExampleName This is an Example of CamelNaming Style


Answer 2

Read BEM (Block-Element-Modifier) ​​as an example article:

https://en.wikipedia.org/ wiki /% D0% 91% D0% AD% D0% 9C

https://en.bem.info/methodology/

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions