自动化测试-java基础知识02
1、标识符
1.1、在源代码中,高亮颜色为黑色时,这个单词就是标识符
1.2、标识符可以标识 类名,方法名,变量名,接口名,常量名
1.3、驼峰命名法
1.3.1 类:所有单词首字母大写,Student,HelloWord, HelloJava
1.3.2 方法,变量:除了第一个单词,其余首字母大写,delete,getMax,findAllStudwnt
2、注释
2.1、通过注释提高程序的可读性,使java程序的条理更加清晰
2.2、单行注释 // 多行注释 /* / 文档注释 、/* */
3、关键字
3.1 java中包含特定含义的英文单词。关键字不能用作变量名,方法名,类名,包名, class public void
4.变量
4.1、变量是用例存储数据的
4.2、命名规范:不能以数字开头,其余部分可以包括数字,字母,下划线,$符号
4.3、为了方便记忆,以后都使用驼峰命名法
5、变量类型
5.1 基本数据类型
5.1.1 存储具体的值
5.1.2 四类八种
5.2 引用数据类型
5.2.1 类,数组,枚举
5.2.2 存储的是地址值
6、八大基本数据类型
6.1 布尔类:boolean 1个字节 true false
6.2 整数类
byte 1个字节 -128 到 127
short 2个字节 -32768 到 32767
int 4个字节 -2147483648 到 2147483648
long 8个字节
6.3 浮点类
float 4个字节
double 8个字节
6.4 字符类
char 2个字节 一个字符 ’ ’
7、变量赋值引用
package hello2;//包
public class Hello2 {//声明 定义一个公开的类,名字叫 hello2
public static void main(String[] args) {
//数据类型 变量名 = 值
boolean bool1 = true;
boolean bool2 = false;
System.out.println(bool1);
System.out.println(bool2);
byte b1 = -128;
byte b2 = 127;
System.out.println(b1);
System.out.println(b2);
short s1 = 1000;
System.out.println(s1);
int i = 1000;
System.out.println(i);
long l =200000L;//注意 加上L 代表是long类型
System.out.println(l);
float f1 = 3.14F;//加上F 代表是float 不加就会报错
System.out.println(f1);
double d1 = 3.14D;//加上 D 代表是 double类型
System.out.println(d1);
char a= ' a';
System.out.println(a);
}
}
8、字符串
8.1 字符串的使用
格式1 String s = “张三”;
格式2 (面向对象)String s = new String (“李思”);
字符串拼接 使用 + 号可以对字符串进行拼接
8.2 代码示例
package hello2;//包
public class Hello2 {//声明 定义一个公开的类,名字叫 hello2
//字符串基本的定义方式
public static void main(String[] args) {
String s = "张三";
System.out.println(s);
s= "李四";
System.out.println(s+"想做一个好人");
String s2 = s+"不想秃头";
System.out.println(s2);
}
}