天猫技术部Java面试宝典2019年最新版!(附答案+解析)

Tips

该宝典集合了阿里面试中遇到的问题,是程序员找工作面试时常见的面试题目,为广大学子提供真实的面试体验,学习面试技巧,让自己在未来的面试中能得心应手。希望大家都能顺利地通过面试,拿到自己心仪的offer~


P.S.题做完了,记得找我对答案哦~

01单选题

1、覆盖(重写)与重载的关系是()。

A.覆盖(重写)只有出现在父类与子类之间,而重载可以出现在同一个类中

B.覆盖(重写)方法可以有不同的方法名,而重载方法必须是相同的方法名

C.final修饰的方法可以被覆盖(重写),但不能被重载

扫描二维码关注公众号,回复: 5363619 查看本文章

D.覆盖(重写)与重载是同一回事

2、不考虑反射机制,一个子类显式调用父类的构造器必须用super关键字。( )

A.正确

B.错误

3、在使用 interface 声明一个外部接口时,只可以使用( )修饰符修饰该接口。

A.private

B.protected

C.private protected

D.public

4、假定AB为一个类,则执行 “AB ab = new AB(a,5);”语句时将自动调用该类的(    )。

A.带参构造函数

B.无参构造函数

C.拷贝构造函数

D.重载赋值运算

5、下列Java常见事件类中哪个是鼠标事件类?() 

A.InputEvent

B.KeyEvent

C.MouseEvent

D.WindowEvent

6、代码

 

System.out.println(10%3*2);

将打印?()

A.1

B.2

C.4

D.6

7、以下关于集合类ArrayList 、 LinkedList 、 HashMap描述错误的是()

A.HashMap实现Map接口,它允许任何类型的键和值对象,并允许将null用作键或值

B.ArrayList和LinkedList均实现了List接口

C.添加和删除元素时,ArrayList的表现更佳

D.ArrayList的访问速度比LinkedList快

其实做为一个开发者,有一个学习的氛围跟一个交流圈子特别重要这里我推荐一个Java交流群664389243,不管你是小白还是大牛欢迎入驻,大家一起交流成长!

8、在开发中使用泛型取代非泛型的数据类型(比如用ArrayList<String>取代ArrayList),程序的运行时性能会变得更好。() 

A.正确

B.错误

9、下面哪个选项正确创建socket连接()

A.Socket s = new Socket(8080);

B.Socket s = new Socket(“192.168.1.1”,8080)

C.SocketServer s = new Socket(8080);

D.Socket s = new SocketServer(“192.168.1.1”,8080)

10、在 Java 中,属于整数类型变量的是()

A.single

B.double

C.byte

D.char

11、列表(List)和集合(Set)下面说法正确的是?  ( )

 A.Set中至多只能有一个空元素

B.List中至多只能有一个空元素

C.List和Set都可以包含重复元素的有序集合

D.List和Set都是有序集合

12、关于C++/JAVA类中static 成员和对象成员的说法正确的是?()

A.static 成员变量在对象构造时生成

B.static 成员函数在对象成员函数中无法调用

C.虚成员函数不可能是static 成员函数

D.static 成员函数不能访问static 成员变量

13、下面的程序编译运行后,在屏幕上显示的结果是()

public class test {

public static void main(String args[]) {

int x,y;

x=5>>2;

y=x>>>2;

System.out.println(y);

}

}

A.0

B.2

C.5

D.80

14、在Java中,以下关于方法重载和方法重写描述正确的是?()

A.方法重载和方法的重写实现的功能相同

B.方法重载出现在父子关系中,方法重写是在同一类中

C.方法重载的返回值类型必须一致,参数项必须不同

D.方法重写的返回值类型必须相同或相容。

小编整理了一些面试题,由于平台不能上传文件,需要的可以加小编QQ群664389243,从里面获取文档,也欢迎招聘者,找工作的进群,给大家提供一个更大的平台(希望可以帮助到大家)

15、下面有个hibernate延迟加载,说法错误的是?()

A.Hibernate2延迟加载实现:a)实体对象 b)集合(Collection)

B.Hibernate3 提供了属性的延迟加载功能

C.get支持延迟加载,load不支持延迟加

D.hibernate使用Java反射机制,而不是字节码增强程序来实现透明性

16、Test.main()函数执行后的输出是( )

class Test {

    public static void main(String[] args) {

        System.out.println(new B().getValue());

    }

    static class A {

        protected int value;

        public A (int v) {

            setValue(v);

        }

        public void setValue(int value) {

            this.value= value;

        }

        public int getValue() {

            try {

                value ++;

                return value;

            } finally {

                this.setValue(value);

                System.out.println(value);

            }

        }

    }

    static class B extends A {

        public B () {

            super(5);

            setValue(getValue()- 3);

        }

        public void setValue(int value) {

            super.setValue(2 * value);

        }

    }

}

A.6 7 7

B.22 34 17

C.22 74 74

D.11 17 34

17、下面哪个不对?()

A.RuntimeException is the superclass of those exceptions that can be thrown during the normal operation of the Java Virtual Machine.

B.A method is not required to declare in its throws clause any subclasses of RuntimeExeption that might be thrown during the execution of the method but not caught

C.An RuntimeException is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch.

D.NullPointerException is one kind of RuntimeException

18、下列程序的运行结果()

public void getCustomerInfo() {

        try {

            // do something that may cause an Exception

        } catch (java.io.FileNotFoundException ex) {

            System.out.print("FileNotFoundException!");

        } catch (java.io.IOException ex) {

            System.out.print("IOException!");

        } catch (java.lang.Exception ex) {

            System.out.print("Exception!");

        }

    }

A.IOException!

B.IOException!Exception!

C.FileNotFoundException!IOException!

D.FileNotFoundException!IOException!Exception!

19、下面有关java hashmap的说法错误的是?()

A.HashMap 的实例有两个参数影响其性能:“初始容量” 和 “加载因子”。

B.HashMap 的实现不是同步的,意味着它不是线程安全的

C.HashMap通过开放地址法解决哈希冲突

D.HashMap中的key-value都是存储在Entry数组中的

20、下列哪个说法是正确的()

A.ConcurrentHashMap使用synchronized关键字保证线程安全

B.HashMap实现了Collction接口

C.Array.asList方法返回java.util.ArrayList对象

D.SimpleDateFormat是线程不安全的

21、关于sleep()和wait(),以下描述错误的一项是( )

A.sleep是线程类(Thread)的方法,wait是Object类的方法;

B.sleep不释放对象锁,wait放弃对象锁

C.sleep暂停线程、但监控状态仍然保持,结束后会自动恢复

D.wait后进入等待锁定池,只有针对此对象发出notify方法后获得对象锁进入运行状态

22、下面哪一项不属于优化Hibernate所鼓励的?()

A.使用单向一对多关联,不使用双向一对多

B.不用一对一,用多对一取代

C.配置对象缓存,不使用集合缓存

D.继承类使用显式多态

23、ResultSet中记录行的第一列索引为?()

A.-1

B.0

C.1

D.以上都不是

24、jre 判断程序是否执行结束的标准是()

A.所有的前台线程执行完毕

B.所有的后台线程执行完毕

C.所有的线程执行完毕

D.和以上都无关

02

不定项选择题

25、给定以下JAVA代码,这段代码运行后输出的结果是()

public class Test

{  

    public static int aMethod(int i)throws Exception

    {

        try{

            return i/10;

        }

        catch (Exception ex)

        {

            throw new Exception("exception in a aMethod");

        }finally{

      System.out.printf("finally");

        }

    public static void main(String[] args){

        try

        {

            aMethod(0);

        }

        catch (Exception ex)

        {

            System.out.printf("exception in main");

        }

        System.out.printf("finished");

    }

}

A.exception in main finished

B.finally finished

C.exception in main finally

D.finally exception in main finally

26、Why would a responsible Java programmer want to use a nested class?()

A.To keep the code for a very specialized class in close association with the class it works with.

B.To support a new user interface that generates custom events.

C.To impress the boss with his/her knowledge of Java by using nested classes all over the place.

27、下列选项中是正确的方法声明的是?()

A.protected abstract void f1();

B.public final void f1() {}

C.static final void fq(){}

D.private void f1() {}

28、在 hibernate 开发中,关于 POJO 类对象的状态说法正确的是()。

A.自由状态(Transient):实体在内存中自由存在,与数据库中的记录无关

B.持久状态(Persistent):实体处于由Hibernate框架所管理的状态,对应了数据库中的一条记录,同时与某个session实例发生了关联

C.游离状态(Detached):在session 关闭之后,可以使对象从持久状态转换到游离状态

D.不能将对象从游离状态转换成持久态

29、以下说法错误的是()

A.其他选项均不正确

B.java线程类优先级相同

C.Thread和Runnable接口没有区别

D.如果一个类继承了某个类,只能使用Runnable实现线程

30、Model-View-Controller(MVC) is an architectural pattern that frequently used in web applications. Which of the following statement(s) is(are) correct?()

A.Models often represent data and the business logics needed to manipulate the data in the application

B.A view is a (visual) representation of its model. It renders the model into a form suitable for interaction, typically a user interface element

C.A controller is the link between a user and the system. It accepts input from the user and instructs the model and a view to perform actions based on that input

D.The common practice of MVC in web applications is, the model receives GET or POST input from user and decides what to do with it, handing over to controller and which hand control to views(HTML-generating components)

E.None of the above

03

填空题

1、过滤字节流输出都是____类的子类。

2、Java 源文件最多只能有一个____类,其他的类个数不限。

3、线程包含____、____ 、____、____ 和____5个状态。

4、Java的特点包含____ 、____ 、____、____和____ 。

5、JSP中的include指令的作用是____ 。

6、Java的基本类型包含____、____、____、____、____、____、____ 和____。

7、自定义的异常类一般直接或间接继承自____类。

8、面向过程编程模式的程序的处理过程为____。

9、Java中I/O流是由____包来实现的。

10、要通过互联网进行通信,至少需要一对套接字,一个运行于客户机端,称之为____,另一个运行于服务器端,称之为____。

11、接口使用____关键字声明。

12、被继承的类一般称为____,继承的类称为____ 。

13、方法____与指定的URL建立连接并返回InputStream类的对象以从这一连接中读取数据。

14、Java源程序是由类定义组成的,每个程序中可以定义若干个类,但是只有一个类是主类。在Java  Application中,这个主类是指包含____方法的类,在Java Applet里,这个主类是一个系统类____ 的子类。

15、我们将覆盖在一个城市、一个国家或许多国家的计算机网络称为____,而仅覆盖在同一建筑内、同一大学或方圆几公里之内计算机网络称为____,介于二者之间的计算机网络称为____ 。

04

问答题

1、什么是Java虚拟机?为什么Java被称作是“平台无关的编程语言”?

2、JDK和JRE的区别是什么?

3、”static”关键字是什么意思?Java中是否可以覆盖(override)一个private或者是static的方法?

4、是否可以在static环境中访问非static变量?

5、Java支持的数据类型有哪些?什么是自动拆装箱?

6、Java中的方法覆盖(Overriding)和方法重载(Overload)是什么意思?

7、Java中,什么是构造方法?什么是构造方法重载?什么是复制构造方法?

8、Java支持多继承么?

9、接口和抽象类的区别是什么?

10、什么是值传递和引用传递?

11、进程和线程的区别是什么?

12、创建线程有几种不同的方式?你喜欢哪一种?为什么?

13、概括的解释下线程的几种可用状态。

14、同步方法和同步代码块的区别是什么?

15、在监视器(Monitor)内部,是如何做线程同步的?程序应该做哪种级别的同步?

16、什么是死锁(deadlock)?

17、如何确保N个线程可以访问N个资源同时又不导致死锁?

18、Java集合类框架的基本接口有哪些?

19、为什么集合类没有实现Cloneable和Serializable接口?

20、什么是迭代器(Iterator)?

21、Iterator和ListIterator的区别是什么?

22、快速失败(fail-fast)和安全失败(fail-safe)的区别是什么?

23、Java中的HashMap的工作原理是什么?

24、hashCode()和equals()方法的重要性体现在什么地方?

25、HashMap和Hashtable有什么区别?

26、数组(Array)和列表(ArrayList)有什么区别?什么时候应该使用Array而不是ArrayList?

27、ArrayList和LinkedList有什么区别?

28、Comparable和Comparator接口是干什么的?列出它们的区别。

29、什么是Java优先级队列(Priority Queue)?

30、你了解大O符号(big-O notation)么?你能给出不同数据结构的例子么?

31、如何权衡是使用无序的数组还是有序的数组?

32、Java集合类框架的最佳实践有哪些?

33、Enumeration接口和Iterator接口的区别有哪些?

34、HashSet和TreeSet有什么区别?

35、Java中垃圾回收有什么目的?什么时候进行垃圾回收?

36、System.gc()和Runtime.gc()会做什么事情?

37、finalize()方法什么时候被调用?析构函数(finalization)的目的是什么?

38、如果对象的引用被置为null,垃圾收集器是否会立即释放对象占用的内存?

39、Java堆的结构是什么样子的?什么是堆中的永久代(Perm Gen space)?

40、串行(serial)收集器和吞吐量(throughput)收集器的区别是什么?

41、在Java中,对象什么时候可以被垃圾回收?

42、JVM的永久代中会发生垃圾回收么?

43、Java中的两种异常类型是什么?他们有什么区别?

44、Java中Exception和Error有什么区别?

45、throw和throws有什么区别?

46、异常处理完成以后,Exception对象会发生什么变化?

47、finally代码块和finalize()方法有什么区别?

48、什么是servlet?

49、解释一下servlet的生命周期。

50、当servlet被载入的时候会发生什么?


今天给大家的分享就到这吧!有收获,需要面试资料或者喜欢小编的可以关注小编同时也欢迎大家加入小编的Java交流群664389243,大家一起交流成长!

猜你喜欢

转载自blog.csdn.net/weixin_42784331/article/details/88045936