简体   繁体   中英

How do you organize a Java bean properties name?

Refer to this , I wonder how to pick a 'properly' name for Java bean property?

Way 1:

  public Class People{

   private Integer peopleId;

   private String petName;

   ....
}

Way 2:

public Class People{

   private Integer people_id;

   private String pet_name;

   ....
}

Well for java, the usual convention is using the lower camel case for variables so I think the right choice would be peopleId , and upper camel case for class names.

This is given in the document you have referred. Have a look at this

proper use of _ is only when you can't show the start and ending of more-than-one words variable(to show it meaningful name clearly). For example:

peopleId - Uppercase I indicate that it is a second word

when your variable name is PEOPLEID (normally constant variable) use PEOPLE_ID

Java naming conventions says that you should:

  • Use mixedCase for methods/variables

  • CamelCase for classes/interfaces.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM