初级Java程序员面试题


Posted in 面试题 onMarch 03, 2016
Compare and contrast (don’t you love that phrase?) the modifiers public, private, protected and default.
Compare an interface to an abstract class and give an example of when you might use one of each.
What does the modifier final mean to a class and a variable?
What is overloading and why might you use it?
What is garbage collection and how does it work in java?
How do you make a Thread in java?
Write a generic main method and explain what each item in the method signature means.
Explain how try/catch/throw/finally work.
What is an Iterator and how do you use it?
What are generics?
1. What is the purpose of finalization? – The purpose of finalization is to give an unreachable object the opportunity to perform any cleanup processing before the object is garbage collected.
2. What is the difference between the Boolean & operator and the && operator? – If an expression involving the Boolean & operator is evaluated, both operands are evaluated. Then the & operator is applied to the operand. When an expression involving the && operator is evaluated, the first operand is evaluated. If the first operand returns a value of true then the second operand is evaluated. The && operator is then applied to the first and second operands. If the first operand evaluates to false, the evaluation of the second operand is skipped.

3. How many times may an object’s finalize() method be invoked by the garbage collector? – An object’s finalize() method may only be invoked once by the garbage collector.
4. What is the purpose of the finally clause of a try-catch-finally statement? – The finally clause is used to provide the capability to execute code no matter whether or not an exception is thrown or caught.
5. What is the argument type of a program’s main() method? – A program’s main() method takes an argument of the String[] type.
6. Which Java operator is right associative? – The = operator is right associative.
7. Can a double value be cast to a byte? – Yes, a double value can be cast to a byte.
8. What is the difference between a break statement and a continue statement? – A break statement results in the termination of the statement to which it applies (switch, for, do, or while). A continue statement is used to end the current loop iteration and return control to the loop statement.
9. What must a class do to implement an interface? – It must provide all of the methods in the interface and identify the interface in its implements clause.
10. What is the advantage of the event-delegation model over the earlier event-inheritance model? – The event-delegation model has two advantages over the event-inheritance model. First, it enables event handling to be handled by objects other than the ones that generate the events (or their containers). This allows a clean separation between a component’s design and its use. The other advantage of the event-delegation model is that it performs much better in applications where many events are generated. This performance improvement is due to the fact that the event-delegation model does not have to repeatedly process unhandled events, as is the case of the event-inheritance model.
11. How are commas used in the intialization and iteration parts of a for statement? – Commas are used to separate multiple statements within the initialization and iteration parts of a for statement.
12. What is an abstract method? – An abstract method is a method whose implementation is deferred to a subclass.
13. What value does read() return when it has reached the end of a file? – The read() method returns -1 when it has reached the end of a file.
14. Can a Byte object be cast to a double value? – No, an object cannot be cast to a primitive value.
15. What is the difference between a static and a non-static inner class? – A non-static inner class may have object instances that are associated with instances of the class’s outer class. A static inner class does not have any object instances.
16. If a variable is declared as private, where may the variable be accessed? – A private variable may only be accessed within the class in which it is declared.
17. What is an object’s lock and which object’s have locks? – An object’s lock is a mechanism that is used by multiple threads to obtain synchronized access to the object. A thread may execute a synchronized method of an object only after it has acquired the object’s lock. All objects and classes have locks. A class’s lock is acquired on the class’s Class object.
18. What is the % operator? – It is referred to as the modulo or remainder operator. It returns the remainder of dividing the first operand by the second operand.
19. When can an object reference be cast to an interface reference? – An object reference be cast to an interface reference when the object implements the referenced interface.
20. Which class is extended by all other classes? – The Object class is extended by all other classes.
21. Can an object be garbage collected while it is still reachable? – A reachable object cannot be garbage collected. Only unreachable objects may be garbage collected.
22. Is the ternary operator written x : y ? z or x ? y : z ? – It is written x ? y : z.
23. How is rounding performed under integer division? – The fractional part of the result is truncated. This is known as rounding toward zero.
24. What is the difference between the Reader/Writer class hierarchy and the InputStream/OutputStream class hierarchy? – The Reader/Writer class hierarchy is character-oriented, and the InputStream/OutputStream class hierarchy is byte-oriented.
25. What classes of exceptions may be caught by a catch clause? – A catch clause can catch any exception that may be assigned to the Throwable type. This includes the Error and Exception types.
26. If a class is declared without any access modifiers, where may the class be accessed? – A class that is declared without any access modifiers is said to have package access. This means that the class can only be accessed by other classes and interfaces that are defined within the same package.
27. Does a class inherit the constructors of its superclass? – A class does not inherit constructors from any of its superclasses.
28. What is the purpose of the System class? – The purpose of the System class is to provide access to system resources.
29. Name the eight primitive Java types. – The eight primitive types are byte, char, short, int, long, float, double, and boolean.
30. Which class should you use to obtain design information about an object? – The Class class is used to obtain information about an object’s design.

Tags in this post...

面试题 相关文章推荐
Java中有几种方法可以实现一个线程?用什么关键字修饰同步方法?stop()和suspend()方法为何不推荐使用?
Aug 04 面试题
描述Cookie和Session的作用,区别和各自的应用范围,Session工作原理
Mar 25 面试题
腾讯技术类校园招聘笔试试题
May 06 面试题
利用指针变量实现队列的入队操作
Apr 07 面试题
database面试题
Mar 28 面试题
MySQL面试题
Jan 12 面试题
Javascript如何发送一个Ajax请求
Jan 26 面试题
什么是makefile? 如何编写makefile?
Jan 02 面试题
如何利用find命令查找文件
Nov 18 面试题
介绍一下Linux中的链接
May 28 面试题
面向对象设计的原则是什么
Feb 13 面试题
GWT都有什么特性
Dec 02 面试题
高级Java程序员面试题
Jun 23 #面试题
Set里的元素是不能重复的,那么用什么方法来区分重复与否呢? 是用==还是equals()? 它们有何区别?
Jul 27 #面试题
高级Java程序员面试要点
Aug 02 #面试题
什么是抽象
Dec 13 #面试题
short s1 = 1; s1 = s1 + 1;有什么错? short s1 = 1; s1 += 1;有什么错?
Sep 26 #面试题
什么是封装
Mar 26 #面试题
abstract class和interface有什么区别
Aug 04 #面试题
You might like
PHP获取网卡地址的代码
2008/04/09 PHP
php中如何防止表单的重复提交
2013/08/02 PHP
PHP无限分类(树形类)
2013/09/28 PHP
php将url地址转化为完整的a标签链接代码(php为url地址添加a标签)
2014/01/17 PHP
PHP实现的登录,注册及密码修改功能分析
2016/11/25 PHP
document.compatMode介绍
2009/05/21 Javascript
JQuery的ready函数与JS的onload的区别详解
2013/11/21 Javascript
js的Boolean对象初始值示例
2014/03/04 Javascript
解析Node.js基于模块和包的代码部署方式
2016/02/16 Javascript
深入理解Webpack 中路径的配置
2017/06/17 Javascript
详解Vue-axios 设置请求头问题
2018/12/06 Javascript
node(koa2) web应用模块介绍详解
2019/03/29 Javascript
vue 虚拟DOM的原理
2020/10/03 Javascript
解决vue打包 npm run build-test突然不动了的问题
2020/11/13 Javascript
Android应用开发中Action bar编写的入门教程
2016/02/26 Python
Python使用Selenium+BeautifulSoup爬取淘宝搜索页
2018/02/24 Python
pandas 将list切分后存入DataFrame中的实例
2018/07/03 Python
详解Numpy中的数组拼接、合并操作(concatenate, append, stack, hstack, vstack, r_, c_等)
2019/05/27 Python
解决python多行注释引发缩进错误的问题
2019/08/23 Python
使用pyhon绘图比较两个手机屏幕大小(实例代码)
2020/01/03 Python
Python调用飞书发送消息的示例
2020/11/10 Python
Python加载数据的5种不同方式(收藏)
2020/11/13 Python
一文带你掌握Pyecharts地理数据可视化的方法
2021/02/06 Python
瑞士最大的图书贸易公司:Orell Füssli
2019/12/28 全球购物
JavaScript获取当前url根目录(路径)
2014/02/19 面试题
升职自荐信
2013/11/28 职场文书
房屋改造计划书
2014/01/10 职场文书
会计岗位说明书
2014/07/29 职场文书
庆祝儿童节标语
2014/10/09 职场文书
教师批评与自我批评范文
2014/10/15 职场文书
公民授权委托书
2014/10/15 职场文书
全陪导游词
2015/02/04 职场文书
美术教师个人工作总结
2015/02/06 职场文书
学术研讨会主持词
2015/07/04 职场文书
vue3使用vue-router的完整步骤记录
2021/06/20 Vue.js
英国数字版游戏销量周榜公布 《小缇娜的奇幻之地》登顶
2022/04/03 其他游戏