初级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...

面试题 相关文章推荐
PHP如何去执行一个SQL语句
Mar 05 面试题
请介绍一下Ant
Jul 22 面试题
请用用Java代码写一个堆栈
Jan 26 面试题
华为c/c++笔试题
Jan 25 面试题
将"引用"作为函数参数有哪些特点
Apr 05 面试题
下面关于"联合"的题目的输出是什么
Aug 06 面试题
关于Assembly命名空间的三个面试题
Jul 23 面试题
.NET概念性的面试题
Feb 29 面试题
新媒传信软件测试面试题
Feb 24 面试题
你经历的项目中的SCM配置项主要有哪些?什么是配置项?
Nov 04 面试题
ajax是什么及其工作原理
Feb 08 面试题
Vector, ArrayList, HashTable, HashMap哪些是线程安全的,哪些不是
Oct 12 面试题
高级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
vs中通过剪切板循环来循环粘贴不同内容
2011/04/30 PHP
php中使用parse_url()对网址进行解析的实现代码(parse_url详解)
2012/01/03 PHP
php生成二维码的几种方式整理及使用实例
2013/06/03 PHP
前端必学之PHP语法基础
2016/01/01 PHP
PDO::inTransaction讲解
2019/01/28 PHP
PhpStorm2020 + phpstudyV8 +XDebug的教程详解
2020/09/17 PHP
jQuery Ajax文件上传(php)
2009/06/16 Javascript
计算世界完全对称日的js代码,粗糙版
2011/11/04 Javascript
用js获取电脑信息(是使用与IE浏览器)
2013/01/15 Javascript
javascript中负数算术右移、逻辑右移的奥秘探索
2013/10/17 Javascript
js判断浏览器类型及设备(移动页面开发)
2015/07/30 Javascript
详解JavaScript正则表达式之分组匹配及反向引用
2016/03/09 Javascript
详解js中Number()、parseInt()和parseFloat()的区别
2016/12/20 Javascript
详解基于vue的服务端渲染框架NUXT
2018/06/20 Javascript
vue-cli脚手架build目录下utils.js工具配置文件详解
2018/09/14 Javascript
js限制input只能输入有效的数字(第一个不能是小数点)
2018/09/28 Javascript
mpvue实现左侧导航与右侧内容的联动
2019/10/21 Javascript
JS面试题中深拷贝的实现讲解
2020/05/07 Javascript
JavaScript进阶(四)原型与原型链用法实例分析
2020/05/09 Javascript
vue+elementui实现点击table中的单元格触发事件--弹框
2020/07/18 Javascript
举例简单讲解Python中的数据存储模块shelve的用法
2016/03/03 Python
Python类装饰器实现方法详解
2018/12/21 Python
python自动化测试之如何解析excel文件
2019/06/27 Python
python pandas模块基础学习详解
2019/07/03 Python
全球航班旅行搜索网站:Cheapflights
2017/05/19 全球购物
预订从美国飞往印度的机票:MyTicketsToIndia
2017/05/19 全球购物
介绍一下Ruby的特点
2013/01/20 面试题
社区关爱留守儿童活动方案
2014/08/22 职场文书
中队活动总结
2014/08/27 职场文书
信用卡工资证明格式
2014/09/13 职场文书
优秀教师自我评价范文
2014/09/27 职场文书
科学育儿宣传标语
2014/10/08 职场文书
公安个人四风问题对照检查及整改措施
2014/10/28 职场文书
2015年度招聘工作总结
2015/05/28 职场文书
倡议书怎么写?
2019/04/11 职场文书
CSS 文字装饰 text-decoration & text-emphasis 详解
2021/04/06 HTML / CSS