If the name is combined with two words, the second word will start with uppercase letter always such as actionPerformed(), firstName, ActionEvent, ActionListener, etc. Java follows camel-case syntax for naming the class, interface, method, and variable. It may contain digits but not as the first letter. If the name contains multiple words, it should be separated by an underscore(_) such as MAX_PRIORITY. It should be in uppercase letters such as RED, YELLOW. If the name contains multiple words, it should be separated by dots (.) such as java.util, java.lang. It should be a lowercase letter such as java, lang. If the name contains multiple words, start it with the lowercase letter followed by an uppercase letter such as firstName, lastName.Īvoid using one-character variables such as x, y, z. It should not start with the special characters like & (ampersand), $ (dollar), _ (underscore). It should start with a lowercase letter such as id, name. If the name contains multiple words, start it with a lowercase letter followed by an uppercase letter such as actionPerformed(). It should be a verb such as main(), print(), println(). It should be an adjective such as Runnable, Remote, ActionListener. Use appropriate words, instead of acronyms. It should be a noun such as Color, Button, System, Thread, etc. It should start with the uppercase letter. The following table shows the popular conventions used for the different identifiers. Naming Conventions of the Different Identifiers It indicates that less time is spent to figure out what the code does. Readability of Java program is very important. However, it is good to be aware that this method does neither do full case folding nor decomposition and so cannot perform caseless matching as specified in the Unicode standard. Advantage of Naming Conventions in Javaīy using standard Java naming conventions, you make your code easier to read for yourself and other programmers. String.equalsIgnoreCase is the most practical choice for naive case-insensitive string comparison. If you fail to follow these conventions, it may generate confusion or erroneous code. These conventions are suggested by several Java communities such as Sun Microsystems and Netscape.Īll the classes, interfaces, packages, methods and fields of Java programming language are given according to the Java naming convention. Java naming convention is a rule to follow as you decide what to name your identifiers such as class, package, variable, constant, method, etc.īut, it is not forced to follow.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |