Home > Java > Javagetting Started > Introduction to java naming conventions and naming formats

Introduction to java naming conventions and naming formats

王林
Release: 2020-11-18 15:17:51
forward
3176 people have browsed it

Introduction to java naming conventions and naming formats

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{}
Copy after login

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(){}
Copy after login

5. Constant names must be in all uppercase letters

For example:

public static final String GAME_COLOR=”RED”;
Copy after login

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
*/
Copy after login

2. Attribute comments

must be added in front of each attribute. The comment template is as follows:

/** 提示信息 */
private String strMsg = null;
Copy after login

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 异常类型.错误代码 注明从此类方法中抛出异常的说明
*/
Copy after login

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 异常类型.错误代码 注明从此类方法中抛出异常的说明
*/
Copy after login

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
Copy after login

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!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template