java 复习

时间:2023-03-08 18:14:20

整型:

byte 1 short 2 int 4 long 8
0b1001 1_233_32 1341414141414L
java 没有无符号类型
浮点型:
float 4 double 8
12.2f 无后缀为double
Double.isNaN(x) 不能==Double.NaN
BigDecimal 无误差
U+d800~U+DBFF Unicode标准中
java中 char用UTF-16[?]编码描述一个代码单元
Character isJavaIdentifierStart isJavaIdentifierPart
strictfp 严格浮点计算 截断中间结果 可能产生溢出
&&和||关系运算有短路方式 ,& |位运算没有
>>>高位填0 ;>>高位填符号位
对移位运算符右侧参数要进行模32运算(除非左为long型),
java String unicode字符序列
str==null && str.length()!=0
CharSequence char 值的一个可读序列 "abc"
if(Character.isSupplementaryCodePoint(cp))
i +=2;
else
i+=1;
StringBuffer threa_safe
StringBuilder no guarantee of synchronization
Scanner in = new Scanner(System.in); //从控制台读取

控制台读密码:

Console cons = System.console();//eclipse 有bug null 
String username = cons.readLine("username:");
char[] passwd = cons.readPassword("password:");

读文件
Scanner in = new Scanner(Paths.get("D:\\2016\\myfile.txt"));
while(in.hasNextLine()){
System.out.println(in.nextLine());
}
写文件
out = new PrintWriter("myfile2.txt");
out.println("国");
out.close(); out = new PrintWriter("myfile2.txt");
out.println("国");
out.close();

new Object(){}.getClass().getEnclosingClass() //gets class of static method
接口中的内部类自动成为static 和public类
代理类 运行时创建全新的类
Proxy.newProxyinstance(classloader,Class[] interfaces,invocationhandle)
泛型
虚拟机中没有泛型,只有普通方法 和类
桥方法(泛型方法被类型擦出后,编译器生成的方法来限定类型)被合成来保持多态
协变 多态的延伸;逆变 类型精细化

基本类型不能作泛型参数,因为有类型擦出
运行时类型查询只能用于原始类型(非泛型)
不能创建参数化类型的数组 ,但可声明,只是不能 new xx<XX>[]
ArrayList<Pair<String>>
泛型类的静态上下文中类型变量无效
不能抛出或捕获泛型类型实例
String.class 是 Class<String>类的对象

java break label 只能跳出语句块
java 不能在嵌套块中重定义变量
switch case可以是 char byte short int 及常量表达式,字符串字面量
Arrays.toString(a)
int[] ar = {1,2,3}
ar = new int[]{2,3,4}
Arrays.copyOf(nums, 2*nums.length); 增加数组长度
int r = (int)(Math.radom()*n); //小于n的随机数

GregorianCalendar calendar = new GregorianCalendar(year,month,day)
Date hireday = calendar.getTime()
java 没有引用传参
java 可以构造器中调另一个构造器 this(xx,xx)
初始化块{}
Runtime.addShutdownhook()
finalize  gc前调用
不是private static final方法 才能动态绑定
java 中 potected 对子类及同一个包中所有其他类都可见
默认 本包可见
new Arraylist<>()
Number 是 Integer Long Float Double Short Byte 超类