简体   繁体   中英

Java: Method name conventions

This is more out of curiosity than anything else, just wondering what are the most common naming conventions for method names?

Start with a capital

GetName() 

or start lowercase and then capitals for each new word

getName()

or something else.

Java uses camelCase convention for method names.

You can read more about conventions in Java in this document: Code Conventions for the Java Programming Language

In Java, the convention is to have the first word with a lower case, and the rest with upper case.

public void getName()

Also, constants are declared in full capitals:

public final int MAX_USERS

In Java, the naming convention for methods is getName()

Variables also follow the same naming convention as methods, for example. getNameExample

The naming convention used for classes capitalizes every word ex. GetName

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