JAVA基础
注释
- 单行注释
//单行注释
- 多行注释
/*
多行注释
*/
- 文档注释
/***
* ii. ;9ABH,
* SA391, .r9GG35&G
* &#ii13Gh; i3X31i;:,rB1
* iMs,:,i5895, .5G91:,:;:s1:8A
* 33::::,,;5G5, ,58Si,,:::,sHX;iH1
* Sr.,:;rs13BBX35hh11511h5Shhh5S3GAXS:.,,::,,1AG3i,GG
* .G51S511sr;;iiiishS8G89Shsrrsh59S;.,,,,,..5A85Si,h8
* :SB9s:,............................,,,.,,,SASh53h,1G.
* .r18S;..,,,,,,,,,,,,,,,,,,,,,,,,,,,,,....,,.1H315199,rX,
* ;S89s,..,,,,,,,,,,,,,,,,,,,,,,,....,,.......,,,;r1ShS8,;Xi
* i55s:.........,,,,,,,,,,,,,,,,.,,,......,.....,,....r9&5.:X1
* 59;.....,. .,,,,,,,,,,,... .............,..:1;.:&s
* s8,..;53S5S3s. .,,,,,,,.,.. i15S5h1:.........,,,..,,:99
* 93.:39s:rSGB@A; ..,,,,..... .SG3hhh9G&BGi..,,,,,,,,,,,,.,83
* G5.G8 9#@@@@@X. .,,,,,,..... iA9,.S&B###@@Mr...,,,,,,,,..,.;Xh
* Gs.X8 S@@@@@@@B:..,,,,,,,,,,. rA1 ,A@@@@@@@@@H:........,,,,,,.iX:
* ;9. ,8A#@@@@@@#5,.,,,,,,,,,... 9A. 8@@@@@@@@@@M; ....,,,,,,,,S8
* X3 iS8XAHH8s.,,,,,,,,,,...,..58hH@@@@@@@@@Hs ...,,,,,,,:Gs
* r8, ,,,...,,,,,,,,,,..... ,h8XABMMHX3r. .,,,,,,,.rX:
* :9, . .:,..,:;;;::,.,,,,,.. .,,. ..,,,,,,.59
* .Si ,:.i8HBMMMMMB&5,.... . .,,,,,.sMr
* SS :: h@@@@@@@@@@#; . ... . ..,,,,iM5
* 91 . ;:.,1&@@@@@@MXs. . .,,:,:&S
* hS .... .:;,,,i3MMS1;..,..... . . ... ..,:,.99
* ,8; ..... .,:,..,8Ms:;,,,... .,::.83
* s&: .... .sS553B@@HX3s;,. .,;13h. .:::&1
* SXr . ...;s3G99XA&X88Shss11155hi. ,;:h&,
* iH8: . .. ,;iiii;,::,,,,,. .;irHA
* ,8X5; . ....... ,;iihS8Gi
* 1831, .,;irrrrrs&@
* ;5A8r. .:;iiiiirrss1H
* :X@H3s....... .,:;iii;iiiiirsrh
* r#h:;,...,,.. .,,:;;;;;:::,... .:;;;;;;iiiirrss1
* ,M8 ..,....,.....,,::::::,,... . .,;;;iiiiiirss11h
* 8B;.,,,,,,,.,..... . .. .:;;;;iirrsss111h
* i@5,:::,,,,,,,,.... . . .:::;;;;;irrrss111111
* 9Bi,:,,,,...... ..r91;;;;;iirrsss1ss1111
*/
标识符
关键字
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-rujbUTTo-1631290046759)(C:\Users\admin\Pictures\Saved Pictures\JAVA关键字.png)]
abstract | assert | boolean | break | byte |
---|---|---|---|---|
case | catch | char | class | const |
continue | default | do | double | else |
enum | extends | final | finally | float |
for | goto | if | implements | import |
instanceof | int | interface | long | native |
new | package | private | protected | public |
return | strictfp | short | static | super |
switch | synchronized | this | throw | trows |
transient | try | void | volatile | while |
- 不能把关键字作为变量名或方法名
- 标识符是大小写敏感的
- 所有的标识符都应该以字母,美元符($),或者下划线(_)开始
- 首字符之后是字母,美元符($),下划线(_)或数字的任意字符组合
- 可以用中文命名,但一般不建议,也不建议使用拼音
数据类型
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-AkJ9WuD3-1631290046761)(C:\Users\admin\Pictures\Saved Pictures\JAVA数据类型.png)]
public class type {
public static void main(String[] args) {
//整数
int num1 = 10;//最常用
byte num2 = 20;
short num3 = 30;
long num4 = 40L;//Long类型要在数字后面加L
//小数:浮点数
float num5 = 50.1F;//float后面要加个F
double num6 = 3.1415926;
//字符
char name = 'A';//用单引号
String namea = "ABC";//用双引号
//布尔值:是非
boolean flag = true;
//booleab flag = false;
System.out.println(num1);
System.out.println(num2);
System.out.println(num3);
System.out.println(num4);
System.out.println(num5);
System.out.println(num6);
System.out.println(name);
System.out.println(namea);
System.out.println(flag);
}
}
进制和字符拓展
public class Demo01 {
public static void main(String[] args) {
//整数拓展:二进制0b 八进制0 十进制 十六进制0x
int i = 10;//十进制
int i1 = 0b10;//二进制
int i2 = 010;//八进制
int i3 = 0x10;//十六进制
System.out.println(i);
System.out.println(i1);
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);
System.out.println(d);
System.out.println(f==d);
//==================================================
//字符拓展
char c1 = 'a';
char c2 = '中';
System.out.println(c1);
System.out.println((int)c1);//强制转换
System.out.println(c2);
System.out.println((int)c2);//强制转换
//所有的字符本质还是数字
//编码Unicode 表:(97 = a 65 = A) 2字节 0~65535(2的16次方)
//区间范围U0000~UFFFF
char c3 = '\u0061';
System.out.println(c3);//a
//转义字符
// \t 制表符
// \n 换行
System.out.println("Hello\nWorld!");
System.out.println("===========================================");
String sa = new String("hello world");
String sb = new String("hello world");
System.out.println(sa==sb);//不相等
String sc = "hello world";
String sd = "hello world";
System.out.println(sc==sd);//相等
//对象 从内存分析
//布尔值扩展
boolean flag = true;
if (flag==true){}//等价于if (flag){}
//Less is More! 代码要精简易懂
}
}