Home > OS >  Naming convention in java
Naming convention in java

Time:10-17

I'm trying to fix my code and have an issue about naming conventions, I think it should be clinicId not clinic_id but I'm not pretty sure about it. Can someone explain what's wrong with it?

public ArrayList<User> getClinicDoctorList(int clinic_id) throws SQLException{ 

CodePudding user response:

Java naming conventions recommend using camel case for method, class, and variable names. So the suggestion would be to use this signature:

public ArrayList getClinicDoctorList(int clinicId) throws SQLException;

That being said, using clinic_id is in fact legal Java, and the code would compile and run. There are occasions where using underscore in names is required, such as interfacing with a framework which expects this naming convention. One example would be a Java POJO which you intend to serialize out to JSON. In this case, if you wanted JSON keys to be separated by underscore, rather than using camel base, you might also use underscores in the POJO. But in general, the universal convention is to use camel case.

CodePudding user response:

You Can use clinic_id but it not recommended,it is better to use clinicId

some of variable naming conversion is:

  • It should start with a lowercase letter such as id, name.

  • It should not start with the special characters like & (ampersand), $ (dollar), _ (underscore).

  • If the name contains multiple words, start it with the lowercase letter followed by an uppercase letter such as firstName, lastName.

  • Avoid using one-character variables such as x, y, z

  • Related