第一章、JavaSE之开发注意事项

1、Public类

(1)一个源文件中最多只能有一个public类,其他类的个数不限。

public class hello {
    public static void main(String[] args) {
        System.out.println("hello beijing!");
    }
}

class one{}

class two{}
  • 运行结果:生成三个类,每有一个都生成对应的class文件

在这里插入图片描述

(2)一个源文件包含public类,则文件名必须按该类名命名

// 文件名:Hello1.java
public class hello {
    public static void main(String[] args) {
        System.out.println("hello beijing!");
    }
}
  • 运行结果
    在这里插入图片描述

(3)可将main方法写到非public类中,然后指定运行该类

class one{
	    public static void main(String[] args) {
        System.out.println("hello one!");
    }
}

class two{
	    public static void main(String[] args) {
        System.out.println("hello two!");
    }
}
  • 运行结果

在这里插入图片描述

2、转义字符
  • 常用转义字符
转义字符字符描述
\t制表符,实现对齐功能
\n换行符,将当前位置移动到下一行开头
\\\
\“
\‘
\r回车,将当前位置移动到本行开头
  • 范例
package com.lizhi;

public class hello {
    public static void main(String[] args) {
        System.out.println("1 hello \t beijing!");
        System.out.println("2 hello \n beijing!");
        System.out.println("3 hello \\ beijing!");
        System.out.println("4 hello \" beijing!");
        System.out.println("5 hello \' beijing!");
        System.out.println("6 hello \r beijing!");
    }
}
  • 运行结果

在这里插入图片描述

3、注释概述
  • 注释:提高代码阅读性

(1)单行注释

//单行注释

(2)多行注释

/* 注释内容 */

(3)文档注释

/**
	*@author:小明
	*@version:1.0
*/
4、代码规范

(1)命名

  • 包名字母全小写 例如: cn.coderstory.Activity.Main

  • 类,接口首字母大写,其他全小写 例如: class Container

  • 方法,变量 :第二个单词开始首字母大写 例如: seedMessage

  • 常量: 大写,单词用“_”分割 例如: final static MIN_WIDTH = 4

  • 接口 :首字母大写 ,后缀Impl 例如: class ContainerImpl

  • 异常类: 首字母大写, 后缀Exception 例如: DataNotFoundException

  • 抽象类 :首字母大写, 前缀Abstract 例如: AbstractBeanDefinition

  • Test类: 首字母大写, 后缀Test 例如: public Location newLocation()

(2)注释

  • 类/方法:以javadoc的方式来写

  • 其余使用单行/多行注释

(3)编码

  • 源文件使用utf-8编码
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

随缘清风殇

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值