百度Java一面面经
1.int和Integer、long和Long各种相等不相等
2.String a="abc",b="ab"+"c",c=new String("ab")+"c"; ==吗
3.这三个方法的关系,同时执行
public void f1(){
synchronized (this){
System.out.println("F1");
}
}
public void f2(){
synchronized (Integer.class){
System.out.println("F2");
}
}
public synchronized void f3(){
System.out.println("F3");
}
用下面代码测试,一看就知道
class Solution {
public static void main(String[] args){
Solution s = new Solution();
new Thread(new Runnable() { @Override public void run() {
s.f1();
}
}).start();
new Thread(new Runnable() { @Override public void run() {
s.f2();
}
}).start();
new Thread(new Runnable() { @Override public void run() {
s.f3();
}
}).start();
}
public void f1(){
synchronized (this){
try {
for (int i=0;i<10;i++) {
System.out.println("F1");
Thread.sleep(100);
}
}catch (Exception e){
e.printStackTrace();
}
}
}
public void f2(){
synchronized (Integer.class){
try {
for (int i=0;i<10;i++) {
System.out.println("F2");
Thread.sleep(100);
}
}catch (Exception e){
e.printStackTrace();
}
}
}
public synchronized void f3(){
try {
for (int i=0;i<10;i++) {
System.out.println("F3");
Thread.sleep(100);
}
}catch (Exception e){
e.printStackTrace();
}
}
}
5.数据库相关:聚簇索引、非聚簇索引;性别上建索引会怎么样,能加快吗?事务特性;乐观锁,悲观锁;数据库隔离级别;MVCC;为什么limit会越往后越慢;
6.JVM
7.线程怎么新建;循环打印;
8.项目;分布式锁,数据库怎么实现
9.两个栈实现一个队列
#百度##校招##Java工程师##面经#
查看4道真题和解析