全国全国自考Java语言程序设计一试题及参考答案文档格式.docx

上传人:b****6 文档编号:16788628 上传时间:2022-11-26 格式:DOCX 页数:10 大小:81.41KB
下载 相关 举报
全国全国自考Java语言程序设计一试题及参考答案文档格式.docx_第1页
第1页 / 共10页
全国全国自考Java语言程序设计一试题及参考答案文档格式.docx_第2页
第2页 / 共10页
全国全国自考Java语言程序设计一试题及参考答案文档格式.docx_第3页
第3页 / 共10页
全国全国自考Java语言程序设计一试题及参考答案文档格式.docx_第4页
第4页 / 共10页
全国全国自考Java语言程序设计一试题及参考答案文档格式.docx_第5页
第5页 / 共10页
点击查看更多>>
下载资源
资源描述

全国全国自考Java语言程序设计一试题及参考答案文档格式.docx

《全国全国自考Java语言程序设计一试题及参考答案文档格式.docx》由会员分享,可在线阅读,更多相关《全国全国自考Java语言程序设计一试题及参考答案文档格式.docx(10页珍藏版)》请在冰豆网上搜索。

全国全国自考Java语言程序设计一试题及参考答案文档格式.docx

C.mouseMoved(MouseEvent)D.mousePressed(MouseEvent)

7.设已经有Graphics2D对象g2d,Line2D对象line,绘制对象line的代码是()

A.g2d.draw(1ine)B.g2d.drawLine(1ine)

C.1ine.draw()D.1ine.drawLine()

8.设Thread对象thd的优先级为7,thd又创建了另一个Thread对象chd,如果未对chd的优先级进行修改,则chd的优先级为()

A.1B.5

C.7D.10

9.在以下供选择的操作中,File对象能够提供的操作是()

A.删除文件B.读写文件

C.打开文件D.查询文件属性

10.在编写访问数据库的Java程序时,Statement对象的作用是()

A.建立新数据库连接B.设置查询命令

C.创建SQL语句对象D.存储查询结果

二、填空题(本大题共10小题,每小题2分,共20分)

请在每小题的空格中填上正确答案。

错填、不填均无分。

11.Java语言是一种____强类型语言___语言,它约束程序员必须遵守规定编写程序,能让编译器检测出程序中尽可能多的错误。

12.在Java语言中,package_______语句用于表示出现在该文件中的所有类都属于这个程序包。

13.在Java程序系统中,对象之间的交互通过相互发送_____消息__实现。

14.数组每个元素按存储顺序对应一个下标,下标从___0____开始顺序编号。

15.用Swing编写GUI程序时,通常用__Jframe_____类派生的子类创建窗口对象。

16.强制型对话框强制对话过程____不能中断___,直至对话过程结束,才让程序响应对话框以外的事件。

17.在Graphics类中,用于在指定的位置显示字符串的方法是_____darwString()__。

18.在Java中,线程的调度策略采用___抢占式____,优先级高的线程比优先级低的优先执行。

19.字符流数据中使用的Unicode字符有____16___位二进制位。

20.J包中有__InetAddress_____类,它的对象用于存储IP地址和域名。

三、简答题(本大题共6小题,每小题3分,共18分)

21.请使用for循环语句实现计算

的值。

22.请写出Java语言中编写事件处理程序的两种方案。

23.请写出代码段,用来创建一个标签对象lbl,显示文字为“Java”,背景色设为绿色。

24.请写出JComboBox对象上可能发生的两种事件类型的名字。

25.请写出线程从阻塞状态恢复到就绪状态的三种途径。

26.请写出URIConnection类提供的获得输入输出流对象的方法和实现网络连接的方法。

四、程序填空题(本大题共5小题,每空2分,共20分)

27.方法voidmoveOddForward(inta[])的功能是将数组中的所有奇数移到所有偶数之前。

voidmoveOddForward(inta[]){

for(inti=0,odd=0;

________;

i++)

if(________){

intt=a[i];

a[i]=a[odd];

a[odd]=t;

odd++;

}

28.以下程序片段定义由JFrame类派生的子类MyWindowDemo。

类MyWindowDemo的构造方法有五个参数:

窗口的标题名,加入窗口的按钮,按钮的背景颜色,以及窗口的宽和高。

classMyWindowDemoextendsJFrame{

publicMyWindowDemo(Stringname,JButtonbutton,Colorc,intw,inth){

setTitle(name);

setSize(w,h);

ContainercontentPane=_______;

contentPane._______;

button.setBackground(c);

}

29.小应用程序有一个按钮和一个文本区,按钮作为发生键盘事件的事件源,并对键盘

事件实施监视。

程序运行时,先点击按钮,让按钮激活。

以后输入英文字母时,在

文本区显示输入的字母。

importjava.applet.*;

importjavax.swing.*;

importjava.awt.event.*;

publicclassTest29extendsAppletimplements_______{

JButtonbutton=newJButton();

JTextAreatext=newJTextArea(5,20);

publicvoidinit(){

button.addKeyListener(this);

add(button);

add(text);

}

publicvoidkeyPressed(KeyEvente){

intt=e._______;

if(t>

=KeyEvent.VK_A&

&

t<

=KeyEvent.VK_Z){

text.append((char)t+"

"

);

publicvoidkeyTyped(KeyEvente){}

publicvoidkeyReleased(KeyEvente){}

30.以下程序的界面有一个文本区text,一个按钮button。

程序运行时,单击按钮,则

将文本区中的内容输出到out,其中out为BufferWriter类的一个对象。

publicvoidactionPerformed(ActionEvente){

Strings;

if(e._______==button){

try{

out._______(text.getText(),0,(text.getText()).length());

out.flush();

text.setText(null);

System.exit(0);

}catch(IOExceptionexp)

{text.setText("

文件定出错!

\n"

System.exit(-1);

31.数据库连接方法connectByJdbcOdbc()按给定的数据库URL、用户名和密码连接数

据库,如果连接成功,方法返回连接对象,连接不成功,则返回空。

publicstaticConnectionconnectByJdbcOdbc(Stringurl,Stringusemame,Stringpassword){

Connectioncon=null;

try{Class._______("

sun.jdbc.odbc.JdbcOdbcDriver"

}catch(Exceptione){

e.printStackTrace();

returnnull;

con=_______.getConnection(url,usemame,password);

catch(SQLExceptione){

returnnull;

returncon;

五、程序分析题(本大题共5小题,每小题4分,共20分)

32.阅读下列程序,请写出该程序的输出结果。

classTest32a{

Stringname;

intage;

longnumber;

Test32a(longnumber,Stringname,intage){

System.out.println("

Name:

+name);

System.out.println("

Age:

+age);

System.out.println("

Tel:

+number);

}

classTest32bextendsTest32a{

Test32b(longnumber,Stringname,intage,booleanb){

super(number,name,age);

Married:

+b);

}

publicclassTest32{

publicstaticvoidmain(Stringargs[]){

Test32babe=newTest32b(4747,"

Tony"

29,true);

33.阅读下列程序,请写出该程序的输出结果。

classTest33{

StringmyString="

1"

;

publicstaticvoidmain(Stringargs[]){

Test33myObj=newTest33();

myObj.stringModifier(myObj.myString);

+myObj.myString);

voidstringModifier(StringtheString){

theString=theString+"

2"

System.out.print(theString);

34.阅读下列程序,请写出该程序的功能。

importjava.awt.*;

importjava.awt.event.*;

importjava.applet.*;

publicclassTest34extendsAppletimplementsActionListener{

Stringmsg="

"

ButtonbList[]=newButton[3];

publicvoidinit(){

Buttonyes=newButton("

Yes"

Buttonno=newButton("

No"

Buttonmaybe=newButton("

Undecided"

bList[0]=(Button)add(yes);

bList[1]=(Button)add(no);

bList[2]=(Button)add(maybe);

for(inti=0;

i<

3;

i++){bList[i].addActionListener(this);

publicvoidactionPerformed(ActionEventae){

for(inti=0;

i++){

if(ae.getSource()==bList[i]){

msg="

Youpressed"

+bList[i].getLabel();

repaint();

publicvoidpaint(Graphicsg){g.drawString(msg,6,100);

35.阅读下列程序,请写出该程序的功能。

importjavax.swing.*;

importjava.awt.*;

publicclassMenuWindowextendsJFrameimplementsActionListener{

JTextFieldtext=newJTextField();

JMenuBarmenuBar;

JMenumenuFruits;

JMenultemmenultem1,menultem2,menultem3;

publicMenuWindow(){

menuBar=newJMenuBar();

setJMenuBar(menuBar);

menuFruits=newJMenu("

水果"

menuBar.add(menuFruits);

menultem1=newJMenultem("

苹果"

menultem1.addActionListener(this);

menuFruits.add(menultem1);

menultem2=newJMenultem("

桔子"

menultem2.addActionListener(this);

menuFruits.add(menultem2);

menuFruits.addSeparator();

menultem3=newJMenultem("

退出"

menultem3.addActionListener(this);

menuFruits.add(menultem3);

Containercon=getContentPane();

con.add(text);

setSize(200,150);

setVisible(true);

publicvoidactionPerformed(ActionEvente){

if(e.getActionCommand()=="

)System.exit(0);

elsetext.setText(e.getActionCommand());

MenuWindowmw=newMenuWindow();

36.阅读下列程序,请写出该程序的输出结果。

classMyThreadextendsThread{

Stringmessage;

ints;

MyThread(Stringmessage,intsec){this.message=message;

s=sec;

publicvoidrun(){

try{sleep(s);

}catch(InterruptedExceptione){}

System.out.println(message+"

+getPriority());

classThreadTest{

Threadfoo=newMyThread("

Foo"

1000);

foo.setPriority(Thread.MIN_PRIORITY);

foo.start();

Threadbar=newMyThread("

Bar"

800);

bar.setPriority(3);

bar.start();

Threadgar=newMyThread("

Gar"

400);

gar.setPriority(7);

gar.start();

Threadkar=newMyThread("

Kar"

100);

kar.setPriority(Thread.MAX_PRIORITY);

kar.start();

注:

假设处理机中没有其它线程占用资源。

六、程序设计题(本大题共2小题,每小题6分,共12分)

37.请编写一个方法intfindMaximum(int[][]numbers),要求该方法返回二维数组中元素的最大值。

38.小应用程序的paint(Gmphicsg)方法能在屏幕窗口上显示信息和绘图,如果paint()方法能调用repaint()方法,这就能使显示实现动态效果,repaint()方法的功能是先清除paint()方法以前所画的内容,然后再调用paint()方法。

以下要你编写的paint()方法取随机的坐标位置画一个边长为20个像素的红色正方形。

其中随机的坐标位置可以用以下表达式表示:

(int)(Math.random()*100)+10

另要求paint()方法在绘制正方形后暂停100毫秒。

importjava.applet.*;

importjava.awt.*;

publicclassClass1extendsApplet{

publicvoidpaint(Graphicsg){

∥请在以下位置编写代码

 

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 求职职场 > 社交礼仪

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1