JAVA基础知识面试题集

来源:互联网 发布:淘宝客服专用语言 编辑:程序博客网 时间:2024/06/02 06:41

1、下列程序输出的结果是?
public void fun(){
String str1 = "hellworld";
String str2 "hello" + new String("world");
System.out.println("str1 == str2");
}




2、下列关于构造函数说法正确的是?
A、构造函数只在new对象的时候执行
B、构造函数可以和类同名,但是方法名确不可以和类名相同
C、一个类中只能有一个构造函数


3、除了构造函数可以初始化对象之外,还有其他方法吗?


4、下列说法正确的是?
A、AbstractSet继承Set
B、WeakMap继承HashMap
C、LinkList继承List


5、是否存在i<i+1的情况?
6、简述一下StringBuffer 和 StringBuilder的区别?
7、简述一下HashMap的内部结构?
8、下列程序的输出结果:
public static void main(String[] args) {
String s;
System.out.println("s=" + s);
}
A、s=
B、s=null
C、会抛出空指针异常
D、程序无法运行,会有编译错误


9、下列程序运行结果是?


private static Proxy instance = new Proxy();
public static Proxy getInstance(){
return instance;
}
public void test(){
Thread t = new Thread(){
public void run(){
System.out.println("ping");
}
};
t.run();
otherTest();
}

private void otherTest(){
System.out.println("pong");
}

public static void main(String[] args) {
Proxy.getInstance().test();
}

A、pingpong B、pongping C、随机值 D、没有值

10、下列异常中属于编译时异常的是?
A、NullPointerException
B、FileNotFoundException
C、ClassCastException
D、ArrayIndexOutOfBoundsException


11、volatile是否能够保证线程安全性问题?
A、是  B、否


12、下列程序运行结果是?
NULL


13、下列程序的运行结果是() //考察点是指传递和引用传递


private String st;
private char[] ch;

public Proxy(String st, char[] ch){
this.st = st;
this.ch = ch;
}

public static void change(){
char[] ch = {'h', 'h', 'h'};
Proxy proxy = new Proxy("bbb", ch);
test(proxy.st, proxy.ch);
System.out.println("st=" + proxy.st);
System.out.println("ch[]=" + new String(ch).toString());
}

public static void test(String str, char[] ch){
str = "abc";
ch[0] = 'g';
}

public static void main(String[] args) {
Proxy.change();
}

A、abc hhh
B、bbb hhh
C、abc ghh
D、bbb ghh


14、linux查看某个端口是否被占用的命令?
15、linux查看mysql中有多少链接数的命令?
16、ps ef|grep java 的含义是什么? 其中|是什么作用?
17、完全二叉树有500个节点,那么这颗树有多少个叶子节点?
18、linux下如何查看某个进程的CPU使用情况,以及该进程下所有线程下的CPU使用情况?
19、关于HTPP的说法下列真确的是?
A、错误503是指服务器关闭
B、http是无状态的连接
C、http具有获取和请求的功能
D、使用GET命令的时候,获取的资源对象可以存储在URL中
20、说说读写锁和同步锁的区别?
21、下列程序的运行结果是?(静态代码块和非静态代码块以及构造函数三者之间的执行顺序)
//类A
package test;
public class ClassA {
public ClassA(){
System.out.println("ClassA constructor");
}
static{
System.out.println("staic area: ClassA");
}
{
System.out.println("non static area: ClassA");
}
}


//类B
package test;
public class ClassB extends ClassA{
public ClassB(){
System.out.println("ClassB constructor:");
}
static{
System.out.println("staic area: classB" );
}
{
System.out.println("non static area:");
}

public static void main(String[] args) {
new ClassB();
}
}


22、一个类能有多个main方法吗?




23、下列代码运行正常的是?


24、二分法的实现?


25、system.out.println("5" + 2) 结果是多少? 


26、ArrayList array = new ArrayList(20) ; 需要进行几次扩展? 







0 0