目录
1、注释、标识符、关键字
2、数据类型
3、 类型转换
4、 变量、常量
5、运算符
6、包机制、JavaDoc
一、注释、标识符、关键字
①注释
- 单行注释
- 多行注释
- 文档注释
②标识符
标识符注意点
- 所有的标识符都应该以字母(A-Z 或者a-z) ,美元符($) 、或者下划线( )开始
- 首字符之后可以是字母(A-Z 或者a-z) ,美元符($) 、下划线( J或数字的任何字符组合
- 不能使用关键字作为变量名或方法名。
- 标识符是大小写敏感的
- 合法标识符举例: age、$salary、. value、 1_ value
- 非法标识符举例: 123abc、 -salary. #abc
public static void main(String[] args) {
String王者荣耀=“最强王者”;
System.out.printIn(王者荣耀);
}
- 可以使用中文命名,但是一般不建议这样去使用,也不建议使用拼音,很Low
二、数据类型
- 强类型语言:要求变量的使用要严格符合规定,所有变量 必须先定义后才能使用
错误一:
错误二:
正确:- Java的数据类型分为两大类
基本类型(primitive type)
引用类型(reference type)
①基本类型:
//八大基本类型
//整数
int num1 = 10; //最常用
byte num2 = 20;
short num3 = 50;
long num4 = 325L;//Long类型要在数字后面加上L
//小数,浮点数
float num5 = 50.1F;//float类型后面加上F;
double num6 = 3.141592615927;
//字符
char name ='A';
// 字符串 ,String不是关键字,是一个类;
String name2 ="fgdfjk";
//布尔值
boolean flag = true;
boolean flag2 = false;
②引用类型:
问题:什么是字节?
-
位(bit) :是计算机内部数据储存的最小单位,11001100是- 个儿位二进制数。
-
字节(byte) :是计算机中数据处理的基本单位,习惯上用大写B来表示,
-
1B (byte,字节) = 8bit (位)
-
字符:是指计算机中使用的字母、数字、字和符号
-
1bit表示1位,
-
1Byte表示一个字节1B=8b。
-
1024B=1KB .
-
1024KB=1M
-
1024M=1G.
思考:电脑的32位和64位的区别是什么呢?
区别一
- 32位的操作系统只可以支持32位的cpu和操作系统
- 64位的操作系统可以支持64位的cpu和操作系统,
③整数拓展 :进制问题
public class Demo3 {
public static void main(String[] args) {
// 整数拓展 进制问题 二进制:0b 十进制 八进制:0 十六进制:0x
int i = 10;
int i2 = 010;//八进制
int i3 = 0x10;//十六进制
System.out.println(i);
System.out.println(i2);
System.out.println(i3);
}
}
④ 浮点数拓展:银行业务任务
//浮点数扩展 ?银行业务怎么表示
//BigDecimal 数学工具类 完成银行业务的任务
//fLoat 有限的 离散的 舍入误差 大约 接近带不等于
//double
//最好完全使用浮点数进行比较
float f = 0.1f; //0.1
double d = 1.0/10; //0.1
System. out . println(f==d); //false
float d1 = 23131312312312313f;
float d2=d1+1;
System. out . println(d1==d2); //true
}
}
⑤ 字符拓展
char C1 = 'a';
char C2 = '中';
System. out . println(C1);
System. out. println((int)C1); // 强制换行
System. out. println(C2);
System. out . println((int)C2); // 强制换行
//所有的字符本质还是数字
//编码Unicode 2个字节 65536 Excel = 2的16次方 =65536
//97 = a 65 = A
// U0000--uFFFF
char C3 = '\u0061';
System.out.println(C3); //a
⑥转义字符
// \t 制表符
// \n 换行
//....
System.out.println("hello\tworld");
System.out.println("hello\nworld");
⑦骚操作:有关对象
String sa = new String( "hello world");
String sb = new String( "hello world");
System. out. println(sa==sb);
String SC = "hello world";
String sd = "he1lo world";
System. out. println(SC==sd);
//对象从内存分析
⑧布尔类型
//布尔值扩展
boolean flag = true;
//if (flag == true){} == if (flag){}
//代码精炼为主
学习资料来源:狂神说JAVA