注释
什么是注释
- 在我们写代码的时候,当代码量很少时,我们自己可以看得懂,当项目结构一旦复杂起来,我们就需要注释了。
- 注释它并不会被执行,是写给开发人员看的。
注释的种类
单行注释
格式://+内容
ps:只能注释一行。
多行注释
格式:/* */
ps:能注释掉多行,用于注释内容较多时。
文档注释
格式:/** */
ps:知道就行
关键字
Java 语言目前定义了 51 个关键字,这些关键字不能作为变量名、类名和方法名来使用。以下对这些关键字进行了分类。
- 数据类型:boolean、int、long、short、byte、float、double、char、class、interface。
- 流程控制:if、else、do、while、for、switch、case、default、break、continue、return、try、catch、finally。
- 修饰符:public、protected、private、final、void、static、strict、abstract、transient、synchronized、volatile、native。
- 动作:package、import、throw、throws、extends、implements、this、supper、instanceof、new。
- 保留字:true、false、null、goto、const。
标识符
- 所有的标识符都应该以字母(A-Z或者a-z)、美元符($)、或者下划线(_)开始
示例:public static void main(String[] args) { String Ahello = "龙宝~~"; String hello = "龙宝~~"; String $hello = "龙宝~~"; String _hello = "龙宝~~"; //String 2hello = "龙宝~~"; //String #hello = "龙宝~~"; }
ps:注释掉的为程序编译报错,是不能这样命名的。
- 首字符之后可以是字母(A-Z或者a-z)、美元符($)、下划线(_)或者数字的任何字符组合
ps:#和%不能用来命名。 - 标识符是大小写敏感的,它区分大小写。
- ***
可以用中文命名,但不建议这样使用,也不建议使用拼音,毕竟这俩兄弟都不符合规范,嘿嘿。***