掌上明珠Java程序员面试总结
编辑: 面试啦 发布时间: 2023-06-08 11:31:48
1. 分配一个5列6行的字符串数组.
2. 写出下面这段程序的输出
try
{
int i=0;
int i2=3/i;
}catch(ArithmeticException ae){
System.out.println(“数学计算错误”);
}catch(Exception e){
System.out.println(“通用错误”);
}finally{
System.out.println(“计算完成”);
}
3. 我们希望下面这段程序能顺序打出0到9十个数字,请指出错误:
public class Demo{
ArralList queue=new ArrayList();
int nextID=0;
Object lock=new Object();
public static void main(String[] args)
{
new Demo().start();
}
public void start()
{
new Producer().start();
new Producer().start();
new Consumer().start();
new Consumer().start();
}
class Producer implements Runnable{
public void run()
{
while(nextID<10)
{
queue.add(new Integer(nextID++));
synchronized(lock){
try{
lock.notifyAll();
}catch(Exception e){
}
}
try{
Thread.sleep(1000);
}catch(InterruptedException e){
}
}
}
}
class Consumer implements Runnable{
public void run(){
while(true){
if(queue.size()==0)
{
synchronized(lock)
{
try{
lock.wait();
}
catch(Exception e){
}
}
}
System.out.println(queue.remove(0));
}
}
}
}
4. 完成下面的程序,把一个int值保存到byte数组中(高位在前).
int i=13223; byte[] b=new byte[4];
5. 请说明Map(映射表)和Set(集合)这两种数据结构的异同点.
6. 有一个GBK编码的文本文件c:/a.txt(<32k),请写出一段程序,读取它的内容显示在标准输出上.
7. 请完成下面的排序算法
public interface Comparable{
//Compare to another instance
//@return >0 if this is larger,=0 if equal, <0 if this is smaller.
public int compareTo(Object o);
}
public static void sort(Comparable[] arr){
…………
}
2. 写出下面这段程序的输出
try
{
int i=0;
int i2=3/i;
}catch(ArithmeticException ae){
System.out.println(“数学计算错误”);
}catch(Exception e){
System.out.println(“通用错误”);
}finally{
System.out.println(“计算完成”);
}
3. 我们希望下面这段程序能顺序打出0到9十个数字,请指出错误:
public class Demo{
ArralList queue=new ArrayList();
int nextID=0;
Object lock=new Object();
public static void main(String[] args)
{
new Demo().start();
}
public void start()
{
new Producer().start();
new Producer().start();
new Consumer().start();
new Consumer().start();
}
class Producer implements Runnable{
public void run()
{
while(nextID<10)
{
queue.add(new Integer(nextID++));
synchronized(lock){
try{
lock.notifyAll();
}catch(Exception e){
}
}
try{
Thread.sleep(1000);
}catch(InterruptedException e){
}
}
}
}
class Consumer implements Runnable{
public void run(){
while(true){
if(queue.size()==0)
{
synchronized(lock)
{
try{
lock.wait();
}
catch(Exception e){
}
}
}
System.out.println(queue.remove(0));
}
}
}
}
4. 完成下面的程序,把一个int值保存到byte数组中(高位在前).
int i=13223; byte[] b=new byte[4];
5. 请说明Map(映射表)和Set(集合)这两种数据结构的异同点.
6. 有一个GBK编码的文本文件c:/a.txt(<32k),请写出一段程序,读取它的内容显示在标准输出上.
7. 请完成下面的排序算法
public interface Comparable{
//Compare to another instance
//@return >0 if this is larger,=0 if equal, <0 if this is smaller.
public int compareTo(Object o);
}
public static void sort(Comparable[] arr){
…………
}
上一篇:Ejb技术面试题 下一篇:25道Java面试题集合
面试题库导航
- C++面试题
- JAVA面试题
- Oracle面试题
- MySQL面试题
- Linux面试题
- 网络工程师面试题
- 网管面试题
- 软件工程师面试题
- PHP面试题
- .net面试题
- 软件测试面试题
- EJB面试题
- Spring面试题
- Javascript面试题
- Python面试题
- QTP面试题
- Servlet面试题
- J2EE面试题
- Database面试题
- ASP面试题
- Unix面试题
- Loadrunner面试题
- 通信面试题
- 嵌入式面试题
- Ruby面试题
- Delphi面试题
- Mobile开发面试题
- SOA面试题
- JAVA面试题面试题
- 研发工程师面试题
- 软件架构师面试题
- 系统工程师面试题
- Android面试题
- JAVA程序员
- C#面试题