java questions

本文深入探讨了Java中的核心概念和技术,包括类加载机制、静态与动态加载的区别、构造器与普通方法的不同、继承与组合的关系、多态性、封装、动态绑定等。此外,还讨论了抽象类与接口的应用场景、集合框架的使用、线程状态、工厂模式、性能调优策略、内存泄露检测方法等内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.[b]"Explain Java class loaders? If you have a class in a package, what do you need to do to run it? Explain dynamic class loading?"[/b]
[url]http://blog.youkuaiyun.com/duxu2004/article/details/676086[/url]

2. Explain static vs. dynamic class loading?
[url]http://blog.youkuaiyun.com/chiuan/article/details/7022508[/url]
[url]http://blog.youkuaiyun.com/tyrone1979/article/details/1164262[/url]

3. "What is the difference between constructors and other regular methods? What happens if you do not provide a constructor? Can you call one constructor from another? How do you call the superclass’s constructor?"

4."How do you express an ‘is a’ relationship and a ‘has a’ relationship or explain inheritance and composition? What is the difference between composition and aggregation?"

[b]5.What do you mean by polymorphism, inheritance, encapsulation, and dynamic binding?[/b]
polymorphism .[pɔliˈmɔ:fizəm]
inheritance .[ɪnˈherɪtəns]
encapsulation [inˌkæpsjuˈleiʃən]

6.What is the difference between an abstract class and an interface and when should you use them?

7."What is the main difference between an ArrayList and a Vector? What is the main difference between HashMap and Hashtable? What is the difference between a stack and a queue?"

8.Explain the Java Collections Framework?

9.Why do you get a ConcurrentModificationException when using an iterator?
What are some of the best practices relating to Java collection?
[url]http://blog.youkuaiyun.com/rush_gogo/article/details/4170415[/url]

10."What is the difference between “==” and equals(…) method? What is the difference between shallow comparison and deep comparison of objects?"

11."When providing a user defined key class for storing objects in the HashMaps or Hashtables, what methods do you have to provide or override (i.e. method overriding)? Why?"

12.What is the main difference between a String and a StringBuffer class?

[b]13.What is the main difference between pass-by-reference and pass-by-value?[/b]
[url]http://www.iteye.com/topic/202512[/url]
[url]http://blog.youkuaiyun.com/jabyshen007/article/details/1528490[/url]

[b]14.How can you improve Java I/O performance?[/b]
[url]http://codermouse.iteye.com/blog/1110445[/url]
文件IO消耗分析

Linux在操作文件时,将数据放入文件缓存区,直到内存不够或系统要释放内存给用户进程使用。所以通常情况下只有写文件和第一次读取文件时会产生真正的文件IO。
对于Java应用,造成文件IO消耗高主要是多个线程需要进行大量内容写入(例如频繁的日志写入)的动作、磁盘设备本身的处理速度慢、文件系统慢、操作的文件本身已经很大。
从程序的角度而言,造成文件IO消耗严重的原因主要是多个线程在写进行大量的数据到同一文件,导致文件很快变得很大,从而写入速度越来越慢,并造成各线程激烈争抢文件锁。

常用调优方法:
异步写文件
批量读写
限流
限制文件大小

网络IO消耗分析

对于分布式Java应用,网卡中断是不是均衡分配到各CPU(cat/proc/interrupts查看)。
网络IO消耗严重的解决方法
从程序的角度而言,造成网络IO消耗严重的原因主要是同时需要发送或接收的包太多。
常用调优方法:
限流,限流通常是限制发送packet的频率,从而在网络IO消耗可接受的情况下来发送packget。

15.What is the main difference between shallow cloning and deep cloning of objects?
[url]http://blog.youkuaiyun.com/liumingwei2009/article/details/6657881[/url]

16.Where and how can you use a private constructor?
sington

17.What is the difference between final, finally and finalize() in Java?

18.Why would you prefer a short circuit “&&, ||” operators over logical “& , |” operators?

19.How does Java allocate stack and heap memory?

20.What is type casting? Explain up casting vs. down casting? When do you get ClassCastException?

21."Discuss the Java error handling mechanism? What is the difference between Runtime (unchecked) exceptions and checked exceptions? What is the implication of catching all the exceptions with the type “Exception”?"

22.What is the difference between processes and threads?Explain different ways of creating a thread?

23.Briefly explain high-level thread states? Explain thread states and how did it switch What design patter do you know? What is a factory pattern?

[b]24.How would you improve performance of a Java application?[/b]
[url]http://blog.youkuaiyun.com/ajian005/article/details/6422362[/url]

性能调优
1 被动的性能调优 自下而上: 计算机及网络(cpu,内存,文件,I/O,网络,), 操作系统(线程,内存,I/O,网络),
应用服务器和数据库(cpu,内存,文件,I/O,网络,),应用程序
在设计,开发,测试阶段进行。
2 主动的性能调优 自上而下:应用程序,应用服务器和数据库(cpu,内存,文件,I/O,网络,),
操作系统(线程,内存,I/O,网络),计算机及网络(cpu,内存,文件,I/O,网络,)
在测试结束,时间紧迫不能修改代码时,实施,上线,升级时。

被动的性能调优步骤:
(1)计算机及网络,操作系统
1) cpu的监控: Unix/Linux 用 top , vmstat , mpstat 命令查看cpu情况,Windows 任务管理器产看
2) 进程资源的监控: top, prstat
3) 内存的监控:vmstat
4) 磁盘的I/O的监控: iostat
5) 网络的I/O的监控: netstat, netstat -ps tcp
6) 系统锁的监控: plockstat
解决方法,增加硬件,修改操作系统参数
(2)Java虚拟机层次的监控 jps
1) jstat -gcutil 5711000
2) 线程互锁的监控: socket, heap, dump, kill -3 <pid>, ps -ef|grep java
3) 内存泄漏的监控: jmap , jhat , jmap -histo 1123
解决方法: 修改参数
(3)应用服务器,数据库层次的监控
1)EJB Container
2)Web Container
3)HTTP Server
4)JDBC Connection Pool
5)JMS Connection Pool
6)ORM Connection Pool
7)高速缓存命中率问题
解决方法:调整参数
(4)应用代码的跟踪
JVMTI
NetBeans Profiler
profiler.netbeans.org
解决方法:代码分析工具,找到瓶颈,修改代码。

被动性能调优的案例分析:
1 内存泄漏问题 : jstat
2 DB连接池: jmap
kill -3 pid, dump
3 大缓存问题
4 外部命令问题 mpstat
5 文件操作问题

[b]25.How would you detect and minimize memory leaks in Java?[/b]
[url]http://blog.youkuaiyun.com/pkuyjxu/article/details/7329390[/url]

26."What do you know about the Java garbage collector? When does the garbage collection occur? Explain different types of references in Java?"
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值