Accurate coding formats and specifications are very important to programmers. Let’s share with you the naming specifications and naming formats in Java.
1. Naming specifications
(Learning video sharing: java teaching video)
1. All project names are lowercase
2 , The package name should be all lowercase
3. The first letter of the class name should be capitalized. If the class name consists of multiple words, the first letter of each word must be capitalized.
For example:
public class MyFirstClass{}
4. The first letter of variable names and method names must be lowercase. If the name consists of multiple words, the first letter of each word must be capitalized.
For example:
int index=0; public void toString(){}
5. Constant names must be in all uppercase letters
For example:
public static final String GAME_COLOR=”RED”;
6. All naming rules must follow the following rules:
The name can only be composed of letters, numbers, underscores, and $ symbols
It cannot start with a number
The name Keywords in JAVA cannot be used.
Chinese and Pinyin naming are strictly not allowed.
2. Annotation specifications
1. Class annotation
A class annotation must be added in front of each class. The annotation template is as follows:
/** Copyright ©, 2006-2010, ChengDu Lovo info. Co., Ltd. FileName: Test.java 类的详细说明 @author 类创建者姓名 @Date 创建日期 @version 1.00 */
2. Attribute comments
must be added in front of each attribute. The comment template is as follows:
/** 提示信息 */ private String strMsg = null;
3. Method comments
in each method A method comment must be added in front. The comment template is as follows:
/** 类方法的详细使用说明 @param 参数1 参数1的使用说明 @return 返回结果的说明 @throws 异常类型.错误代码 注明从此类方法中抛出异常的说明 */
4. Constructor method comment
A comment must be added in front of each construction method. The comment template is as follows:
/** 构造方法的详细使用说明 @param 参数1 参数1的使用说明 @throws 异常类型.错误代码 注明从此类方法中抛出异常的说明 */
5. Method internal comments
Use single-line or multi-line comments inside the method. The comments are added according to the actual situation.
Such as:
//背景颜色 Color bgColor = Color.RED
Related recommendations: java introductory tutorial
The above is the detailed content of Introduction to java naming conventions and naming formats. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Mac version
God-level code editing software (SublimeText3)