笔试题 看你会几个???????
1.如何改进下面的程序以提高其执行性能?对你的改进作出解释,并写出新的程序。
int i;
URL url = new URL("http://java.sun.com/");
URLConnection javaSite = url.openConnection();
InputStream input = javaSite.getInputStream();
InputStreamReader reader = new InputStreamReader(input);
while ((i = reader.read()) != -1) {
System.out.print(i);
}
2.下面的程序合法吗?
try {
} finally {
}
3.下面的程序片断能捕获什么异常?
catch (Exception e) {
}
这样的异常处理有什么不好吗?
4.下面的程序片断有什么错误吗?它能否通过编译?
try {
} catch (Exception e) {
} catch (ArithmeticException a) {
}