JAVA 基础
/* 注释 8/ 多行注释
/***
* _ooOoo_
* o8888888o
* 88" . "88
* (| -_- |)
* O\ = /O
* ____/`---'\____
* . ' \\| |// `.
* / \\||| : |||// \
* / _||||| -:- |||||- \
* | | \\\ - /// | |
* | \_| ''\---/'' | |
* \ .-\__ `-` ___/-. /
* ___`. .' /--.--\ `. . __
* ."" '< `.___\_<|>_/___.' >'"".
* | | : `- \`.;`\ _ /`;.`/ - ` : | |
* \ \ `-. \_ __\ /__ _/ .-` / /
* ======`-.____`-.___\_____/___.-`____.-'======
* `=---='
*
* .............................................
* 佛祖保佑 永无BUG
*/
标识符注意
-
所有标识符都应该以字母(A-Z或者a-z),美元符(%),下划线(_)开始
-
首字符之后任意字符都可以
-
标识符大小写都可以
数据类型
强类型语言
-
要求变量的使用严格符合规定,所有变量都必须定义后才能使用
基本类型
//八大数据类型
//整数
int num1 = 10; //最常用
byte mun2 = 20;
short num3 = 30;
long num4 = 40L; //Long类型要在数字后面加L
//小数:浮点数
float num5 = 50.1F; //float类型要在数字后面加F
double num6 = 3.1415926;
//字符
char name = '中';
//字符串 String 不是关键字,是类
String name_a = "杨";
//布尔值: 是非
boolean flag = true;
boolean Flag = false;
进制科普
public class Dome3 {
public static void main(String[] args) {
//整数拓展: 进制
//二进制 0b 十进制 八进制 0 十六机制 0x
int i = 10;
int i2 = 010;
int i5 = 011;
int i3 = 0x10;
System.out.println(i5);
System.out.println(i);
System.out.println(i2);
System.out.println(i3);
System.out.println("==========================================");
浮点数拓展
//===================================================================
//浮点数拓展? 银行业务怎么表示? 钱
//===================================================================
//银行业务使用 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); //false
float d1 = 12345678928334743857f;
float d2 = d1 + 1;
System.out.println(d1==d2); //true
字符拓展
//============================================================
//字符拓展?
//============================================================
char c1 = 'A';
char c2 = '中';
System.out.println((int)c1); //(int)强制转换
System.out.println((int)c2); //(int)强制转换
//所有的字符本质都是数字
//编码 Unicode 有一个编码表:97=a 65=A 占2个字节 65536个字符乃至更多
char c3 = '\u0061';
System.out.println(c3); //a
转义字符
//============================================================
//转义字符
// \t 制表符
// \n 换行
//============================================================
System.out.println("Hello\tWorld"); //Hello World
System.out.println("Hello\nWorld");
布尔值
//============================================================
//布尔值拓展
//============================================================
boolean flag = true;
if (flag == true);{} //新手
if (flag); // == true老手
//两个一个意思 相等
//Less is More! 代码要精简易读
}
}
神奇的底层
System.out.println("==========================================");
String sa = new String("Hello,World");
String sb = new String("Hello,World");
System.out.println(sa==sb); //false
String sc = "Hello,World";
String sd = "Hello,World";
System.out.println(sc==sd); //true
//对象 底层

浙公网安备 33010602011771号