最近5年133个Java面试问题列表
最新推荐文章于 2019-02-16 12:17:00 发布
// The standard idiom for using the wait method
synchronized (obj) {
while (condition does not hold)
obj.wait();// (Releases lock, and reacquires on wakeup)
... // Perform action appropriate to condition
}
参见 Effective Java 第 69 条,获取更多关于为什么应该在循环中来调用 wait 方法的内容。byte a= 127;
byte b = 127;
b = a + b;// error : cannot convert from int to byte
b += a; // ok
(因为 a+b 操作会将 a、b 提升为 int 类型,所以将 int 类型赋值给 byte 就会编译出错)// from ArrayList.java JDK 1.7
private static final int DEFAULT_CAPACITY = 10;
//from HashMap.java JDK 7
static final int DEFAULT_INITIAL_CAPACITY= 1 << 4; // aka 16
61)有没有可能两个不相等的对象有有相同的 hashcode?public staticint dateDiff(Dated1, Date d2) throws Exception {
long n1 = d1.getTime();
long n2 = d2.getTime();
long diff = Math.abs(n1- n2);
diff/= 3600 * 1000 * 24;
return diff;
}
87)Java 中,如何将字符串 YYYYMMDD 转换为日期?