”); } Catch(IOException ioe) { } System.out.println(“IO Exception”);} }
A)start( ) B)close( ) C)read( ) D)write( )
(21)在一个线程中调用下列方法,不会改变该线程运行状态的是
A)yield 方法 B)另一个线程的 join 方法
C)sleep 方法 D)一个对象的 notify 方法
(22)在关闭浏览器时调用,能够彻底终止 Applet 并释放该 Applet 所有资源的方法 是
A)stop( ) B)destroy( )
C)paint( ) D)start( )
(23)为了将 HelloApplet(主类名为 HelloApplet.class)嵌入在 greeting.html 文件中,
应该在下列 greeting.html 文件的横线处填入的代码是
A)HelloApplet.class
B)CODE=” HelloApplet.class”
C)CODE=” HelloApplet.class” WIDTH=150 HEIGHT=25
D)CODE=” HelloApplet.class” WIDTH=10 HEIGHT=10
(24)下列变量名的定义中,符合 Java 命名约定的是
A)fieldname B)super C)Intnum D)$number
(25)自定义异常类的父类可以是
A)Error B)VirtuaMachineError
C)Exception D)Thread
(26)阅读下列程序片段 Public void test(){ Try{ sayHello();
system.out.println(“hello”); } catch (ArrayIndexOutOfBoundException e) { System.out.println
(“ArrayIndexOutOfBoundException”); }catch(Exception e){ System.out.println(“Exception”); }finally {
System.out.println(“finally”); } } 如果 sayHello( )方法正常运行,则 test( )方法的运行结果将是
A)Hello B)ArrayIndexOutOfBondsException
C)Exception Finally D)Hello Finally
(27)为使 Java 程序于平台,Java 虚拟机把字节码与各个操作系统及硬件
A)分开 B)结合 C)联系 D)融合
(28)Java 中的基本数据类型 int 在不同的操作系统平台的字长是
A)不同的 B)32 位
C) 位 D)16 位
(29)String、StingBuffer 都是____
A)static B)abstract C)final D)private
(30)下列程序的功能是统计字符串中“array”的个数,在程序的空白处应填入的正确 选项是
public class FindKeyWords{ public static void main(sring[] args){ sting text= “ An array is a data structur that
stores a collection of” + “values of the same type . You access each individual value” + “through an integer
index . For example,if a is an array” + “of inergers, then a[i] is the ith integer in the array.”; Int
arrayCount =0; Int idex = -1; Sting arrarStr =”array”; Index = text.indexof(arrayStr); While(index +
+arrayCount; Index += arrayStr.length(); Index = text.indexof(arrayStr,index); } System.out.println (“the text
contains” + arrayCount + “arrays”); } 0) {
}
A)< B)= C)<= D)>=
(31)构造方法名必须与__ 用它,只能通过 new 调用。
A)类名 B)对象名 C)包名 D)变量名
_A___相同,它没有返回值,用户不能直接调
(32)在多线程并发程序设计中,能够给对象 x 加锁的语句是
A)x.wait( ) B)synchronized(x)
C)x.notify( ) D)x.synchronized( )
(33)Java 中类 ObjectOutputStream 支持对象的写操作,这是一种字节流,它的直 接父类是
A)Writer B)DataOutput
C)OutputStream D)ObjectOutput
(34)在下列程序的空白处,应填入的正确选项是
Import java.io.*; Pulilc class ObjectStreamTest{
Publilc static void main(string args[]) throws IOException{ ObjectOutputStream oos= new ObjectOutputStream (new
FileOutputStream(“serial.bin”)); Java.util.Date d= new Java.util.Date(); Oos (d);
ObjectInputStream ois= new ObjectInputStream(new FileOutputStream(“serial.bin”));
try{ java.util.date restoredDate = (Java.util.Date) ois.readObject(); System.out.println (“read object back from
serial.bin file:” + restoredDate); } Catch (ClassNotFoundException cnf) { System.out.println (“class not found
”); } }
A)WriterObject B)Writer
C)BufferedWriter D)WriterObject
(35)Class 类的对象由____ 提供信息。
A)Java 编译器 B)Java 解释器
C)Java new 关键字 D)Java 类分解器
二、填空题
(6)按照 Java 的线程模型,代码和 【数据】 构成了线程体。
(7) 在多线程程序设计中, 如果采用继承 Thread 类的方式创建线程, 则需要重写 Thread 类的 【run 】 ()方法。
(8)在下列 Java applet 程序的横线处填入代码,使程序完整并能够正确运行。 Import java. awt. *; Import java.
applet. *; Public class Greeting extends applet{ Public void 【 paint】 (Graphics g) { g.drawSting(“how are you!
”,10,10); } }
(9)在 Java 语言中,用 【abstruct 】 修饰符定义的类为抽象类。
(10)在 Java 中,字符是以16位的 【 Unicode】 码表示。
(11)请在下列程序的空白处,填上适当的内容: Import java. awt. *; Import java. util. *; Class BufferTest{ Public
static void main(string args[]) Throws IOException{ FileOutputStream unbuf= new FileOutputStream(“test.one”) ;
BufferedOutputStream buf= new 【BufferedOutputStream】 (new FileOutputStream(“test.two”)); System.out.println (
“write file unbuffered: ” + time(unbuf) + “ms”); System.out.println (“write file buffered: ” + time(buf) +
“ms”); } Static int time (OutputStream os) Throws IOException{ Date then = new Date(); for (int i=0; i<50000;
i++){
os.write(1); } } os.close(); return(int)(()new Date()).getTime() - then.getTime()); }
(12)代码 System.out.println(066)的输出结果是 【 54 】 。
(13)Swing 中用来表示工具栏的类是 javax.swing. 【JToolBa】 。
(14)表达式(10*49.3)的类型是 【double 】 型。
(15)抛出异常的语句是 【 t hrowException】 语句。
二级 java 答案: 1-5:CBDAB 6-10:ACBCD 11-15:BCDDB 16-20:ACBCB 21-25:BBCAC 26-30:DABCD 31-35:ABCDA 1-15 : 14 数据
run BufferedOutputStream
逻辑条件 需求分析 多对多 身份证号码 paint abstruct Unicode 54 JToolBar double t hrowException
2010 年 3 月计算机等级考试二级 Java 笔试试题
一、选择题
(11)Java 中定义常量的保留字是
A)const B)final
C)finally D)native
(12)下列有关 Java 布尔类型的描述中,正确的是
A)一种基本的数据类型,它的类型名称为 boolean
B)用 int 表示类型
C)其值可以赋给 int 类型的变量
D)有两个值,1 代表真,0 代表假
(13)Java 中所有类的父类是
A)Father B)Lang
C)Exception D)Object
(14)下列程序段的输出结果是
int data=0; char k='a',p='f'; data=p-k; system.out.println(data);
A)0 B)a C)f D)5
(15)下列数中为八进制的是
A)27 B)0x25 C)026 D)028
(16)下列方法中,不属于 Throwable 类的方法是
A)printMessage B)getMessage
C)toString D)fillStackTrace
(17)下列程序的输出结果是
public class Test{ public static void main(String[] args){ int [] array={2,4,6,8,10}; int size=6; int result=-1;
try{ for{int i=0;i if(array[i]==20) result=i; } catch(ArithmeticException e){ System.out.println("Catch---1");
catch(ArrayIndexOutOfBoundsException e){ System.out.println("Catch---2"); catch(Exception e){ System.out.println
("Catch---3"); } }
A)Catch---1 B)Catch---2 C)Catch---3 D)以上都不对
(18)下列包中,包含 JOptionPane 类的是
A)javax.swing B)java.lang
C)java.util D)java.applet
(19)下列选项中,与成员变量共同构成一个类的是
A)关键字 B)方法 C)运算符 D)表达式
(20)下列程序的功能是将一个整数数组写入二进制文件。 在程序的下划线处 应填入的选项是 import java.io.*; public class
XieShuzu{ public static void main(String[] a){ int [] myArray={10,20,30,40}; try{ DataOutputStream dos= new
DataOutputStream(new FileOutputStream("ints.dat")); for(int i=0;i< p> dos. _____(myArray[i]); dos.close();
System.out.println("已经将整数数组写入二进制文件:ints.dat"); }catch(IOException ioe)
{System.out.println("IO Exception");} } }
A)writeArray B)writeByte
C)writeInt D)writeDouble
(21)Java 中的抽象类 Reader 和 Writer 所处理的流是
A)图像流 B)对象流
C)字节流 D)字符流
(22)下列叙述中,错误的是
A)内部类的名称与定义它的类的名称可以相同
B)内部类可用 abstract 修饰
C)内部类可作为其他类的成员
D)内部类可访问它所在类的成员
(23)用于在子类中调用被重写父类方法的关键字是
A)this B)super C)This D)Super
(24)下列 Java 语句从指定网址读取 html 文件, 在下划线处应填上的选项是
Reader in=new____(new URL(urlString).openStrream());
A)Reader B)DataOutputStream
C)ByteArrayInputStream D)InputStreamReader
(25)下列不属于表达式语句的是
A)++i; B)--j; C)b#a; D)b*=a;
(26)下列为窗口事件的是
A)MouseEvent B)WindowEvent
C)ActionEvent D)KeyEvent
(27)用鼠标点击菜单项(MenuItem)产生的事件是
A)MenuEvent B)ActionEvent
C)KeyEvent D)MouseEvent
(28)下列不属于逻辑运算符的是
A)! B)|| C)&& D)|
(29)当使用 SomeThread t=new SomeThread()创建一个线程时,下列叙述中 正确的是
A)SomeThread 类是包含 run()方法的任意 java 类
B)SomeThread 类一定要实现 Runnable 接
C)SomeThread 类是 Thread 类的子类
D)SomeThread 类是 Thread 类的子类并且要实现 Runnable 接口
(30)在程序的下划线处应填入的选项是
public class Test_____{ public static void main(String args[]){ Test t = new Test(); Thread tt = new Thread(t);
tt.start(); } public void run(){ for(int i=0;i<5;i++){ system.out.println("i="+i); } } }
A)implements Runnable
B)extends Thread
C)implements Thread
D)extends Runnable
(31)为了支持压栈线程与弹栈线程之间的交互与同步, 在程序的下划线处依 次填入的语句是
public class IntStack{ private int idx=0; private int[] data=new int[8]; public ______ void push(int i){ data
[idx]=i; idx++; _____ } ...... }
A)synchronized() notify()
B)synchronized() this.wait()
C)synchronized() this.notify()
D)synchronized() sleep()
(32)如果线程正处于阻塞状态, 不能够使线程直接进入可运行状态的情况是
A)sleep()方法的时间到
B)获得了对象的锁
C)线程在调用 t.join()方法后,线程 t 结束
D)wait()方法结束
(33)当一个 Applet 被加载,后续对 Applet 生命周期方法的调用中,可能存 在的次序是
A)start(),stop(),destroy()
B)init(),start(),stop(),start(),stop(),destroy()
C)start(),init(),stop(),destroy()
D)init(),start(),destroy()
(34)在 HTML 文件的