In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "what is the java naming convention". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the java naming convention".
01. Package (package)
Package naming should follow the following rules:
It should be all lowercase letters.
An English word with only one natural meaning between the dot separators
Package names are uniformly singular, for example, com.itwanger.util cannot be com.itwanger.utils
In the latest Java programming specification, developers are required to prefix their own defined package names with a unique prefix. Because the domain name on the Internet is not duplicated, most developers use the domain name of their own company (or personal blog) on the Internet as the only prefix for the package. For example, the package name of the code example that appears in my article is package com.itwanger.
02. Class (class)
Class naming should follow the following rules:
Must start with an uppercase letter
Preferably a noun, such as System
Class names use the UpperCamelCase (hump naming) style
Try not to omit the first letter of a word, with the following exceptions: DO/BO/DTO/VO/AO/ PO / UID, etc.
In addition, start with Abstract or Base for an abstract class, end with Exception for an exception class, and end with Test for a test class.
03. Interface (interface)
The naming of interfaces should follow the following rules:
Must start with an uppercase letter
Preferably an adjective, such as Runnable
Try not to omit the first letter of a word.
Let's look at an example:
Interface Printable {}
There are also some rules between the interface and the implementation class
The implementation class is distinguished from the interface by the suffix of Impl, for example, CacheServiceImpl implements the CacheService interface
Alternatively, AbstractTranslator implements the Translatable interface
04, field (field) and variable (variable)
The naming of fields and variables should follow the following rules:
Must start with a lowercase letter
Can contain multiple words, the first letter of the first word is lowercase, and other words are capitalized, such as firstName
It is best not to use a single character, such as int a, unless it is a local variable
Type is closely linked to square brackets to represent an array, for example, string array parameters in the int [] arrayDemo,main method should not be written as String args []
Don't prefix any Boolean variables in the POJO class with is, otherwise some frame parsing will cause serialization errors. I know fastjson.
Avoid using exactly the same naming between the member variables of the subclass and the parent class, or between local variables of different code blocks, making it less understandable. Subclass and parent member variables have the same name, and even variables of type public can be compiled. In addition, it is legal for local variables to have the same name in different blocks of code within the same method.
Counterexample:
Public class ConfusingName {public int stock; / / non-setter/getter parameter name, public void get (String alibaba) {if (condition) {final int money = 666; / /...} for (int I = 0; I < 10) is not allowed as a member variable of this class. Money +) {/ / in the same method body, final int money = 15978; / /.} class Son extends ConfusingName {/ / does not allow the same public int stock; name as the member variable name of the parent class
Constant (constant)
Constant naming should follow the following rules:
It should be all capital letters.
Can contain multiple words, and use "_" connections between words, such as MAX_PRIORITY, to make the semantic expression complete and clear, and not to disrelish the long name.
Can contain a number, but cannot start with a number
Let's look at an example:
Static final int MIN_AGE = 18
06. Method (method)
The naming of methods should follow the following rules:
Must start with a lowercase letter
Preferably a verb, such as print ()
Can contain multiple words, the first letter of the first word is lowercase, the first letter of other words is capitalized, such as actionPerformed ()
Let's look at an example:
Void writeBook () {}
The method naming convention of the Service/DAO layer:
The method of getting a single object is prefixed with get
The method of getting multiple objects is prefixed with list and ends in plural, such as listObjects
The method of obtaining statistical values is prefixed with count.
The method of insertion is prefixed with save/insert
The method of deletion is prefixed with remove/delete
The modified method is prefixed with update
Thank you for your reading, the above is the content of "what is the java naming convention", after the study of this article, I believe you have a deeper understanding of what is the java naming convention, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.