Java精简回忆

27 阅读1分钟

java

数据类型

1.基本数据类型

char【1】可以char=97即ASCII码
byte【1】-128~1278
short【2】-32768~3276716
int【4】-2147483648~214748364732
long【8】264-2^{64}~2632^{63}-164
float【4】
double【8】
boolean【1】

2.引用数据类型

类class 接口interface 数组array

别的转换成String

加个双引号""

String转换成别的

parseXX()

s="123"
int i=Integer.parseInt(s);

image.png

System.out.println(s.charAt(0));//s的第一个字符

但是“hello”转换成整数这种不正确,会抛出一个==异常==,程序终止。

短路与:&&,逻辑与:&

都是 全true 才 true

&& 左边为false,后面就不判了 ------高效

& 后面接着判

数组

堆:动态,分散放,需要手动释放

栈:局部变量,自动释放

数组赋值机制

值传递 就是 值拷贝

int n1 = 10;
int n2 = n1;
n2 = 80;

image.png

引用传递 就是 地址拷贝

int[] arr1 = {1,2,3};
int[] arr2 = arr1;
arr2[0] = 10;

image.png

重载

float hello(int a,int b){
return a+b;
}

float hello(long a,int b){
return a-b;
}

double hello(double a,int b){
return a * b;
}

不看前面是float还是double

不看return

看()里的参数个数,以及类型