在java中,类名通常应该是名词,以大写字母开头的标题形式,每个单词的首字母大写。接口名通常应该是形容词,以大写字母开头的标题形式,每个单词的首字母大写。
为什么应该遵循java命名标准减少阅读和理解源代码所需的工作量。使代码审查能够专注于比语法和命名标准更重要的问题。使代码质量审查工具能够主要关注重要问题而不是语法和风格偏好。不同类型标识符的命名约定包包名应全部小写。示例package com.tutorialspoint;
接口接口名称应以大写字母开头。示例interface tutorialspointinterface { // some statements}
class类名的所有单词都应以大写字符开头。示例class tutorialspointclass { // some statements}
方法方法应该是以小写字母开头,并且每个内部单词的首字母大写的动词。示例class tutorialspointclass { void printmessage() { }}
变量第一个单词应小写,内部单词以大写字母开头。变量名称不应以下划线开头_ 或美元符号 $ 字符。示例class tutorialspointclass { int rollnum; string firstname; string lastname;}
常量所有字符都应为大写。示例class tutorialspointclass { public static final int max_score = 100;}
以上就是为什么我们应该遵循java的命名规范?的详细内容。
