-1

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. What's wrong with it?

public ArrayList<User> getClinicDoctorList(int clinic_id) throws SQLException{
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
abc
  • 23
  • 6
  • [This is the document you're looking for](https://www.oracle.com/technetwork/java/codeconventions-150003.pdf) - so, yes, use `clinicId`. – Dawood ibn Kareem Oct 17 '21 at 06:08
  • 2021??? There ***must*** be a canonical question. What is it? – Peter Mortensen May 14 '22 at 12:47
  • Some candidates: *[Using underscores in Java variables and method names](https://stackoverflow.com/questions/150192/)* (2008), *[Use of underscore in variable and method names](https://stackoverflow.com/questions/16785175/)* (2013), *[Why do we add an _ (underscore) before a variable name?](https://stackoverflow.com/questions/20677249/)* (2013), and *[Variable naming conventions in Java](https://stackoverflow.com/questions/414001/)* (2009). – Peter Mortensen May 14 '22 at 12:47
  • Please don't answer the same beginner questions over and over and over again. Please find the duplicate, indicate it in comments (or vote to close), and find some more interesting question to answer. – Peter Mortensen May 14 '22 at 12:50

3 Answers3

2

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.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
0

You can use clinic_id, but it not recommended. It is better to use clinicId

Some of the variable naming conversions are:

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

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

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

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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Mehdi Varse
  • 271
  • 1
  • 15
-1

For your reference, Here is a detailed view of naming conventions in java.

enter image description here

Since we are referring to a varible of integer type, we can use "clinic_id" or "clinicId" or any other name of your choice, unless naming conventions are not violated. Although, it is always recommended to use Camel Case for naming variables in java ,because:

  • Easy to read
  • Easy to type
  • Easy to understand

On the other hand, the use of underscores within the name can be found while naming ANSI constants in java, like:

"int MIN_WIDTH=4;" "Int MAX_WIDTH=999;"