份Java自考题参考答案docWord下载.docx

上传人:b****4 文档编号:7201706 上传时间:2023-05-08 格式:DOCX 页数:18 大小:37.61KB
下载 相关 举报
份Java自考题参考答案docWord下载.docx_第1页
第1页 / 共18页
份Java自考题参考答案docWord下载.docx_第2页
第2页 / 共18页
份Java自考题参考答案docWord下载.docx_第3页
第3页 / 共18页
份Java自考题参考答案docWord下载.docx_第4页
第4页 / 共18页
份Java自考题参考答案docWord下载.docx_第5页
第5页 / 共18页
份Java自考题参考答案docWord下载.docx_第6页
第6页 / 共18页
份Java自考题参考答案docWord下载.docx_第7页
第7页 / 共18页
份Java自考题参考答案docWord下载.docx_第8页
第8页 / 共18页
份Java自考题参考答案docWord下载.docx_第9页
第9页 / 共18页
份Java自考题参考答案docWord下载.docx_第10页
第10页 / 共18页
份Java自考题参考答案docWord下载.docx_第11页
第11页 / 共18页
份Java自考题参考答案docWord下载.docx_第12页
第12页 / 共18页
份Java自考题参考答案docWord下载.docx_第13页
第13页 / 共18页
份Java自考题参考答案docWord下载.docx_第14页
第14页 / 共18页
份Java自考题参考答案docWord下载.docx_第15页
第15页 / 共18页
份Java自考题参考答案docWord下载.docx_第16页
第16页 / 共18页
份Java自考题参考答案docWord下载.docx_第17页
第17页 / 共18页
份Java自考题参考答案docWord下载.docx_第18页
第18页 / 共18页
亲,该文档总共18页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

份Java自考题参考答案docWord下载.docx

《份Java自考题参考答案docWord下载.docx》由会员分享,可在线阅读,更多相关《份Java自考题参考答案docWord下载.docx(18页珍藏版)》请在冰点文库上搜索。

份Java自考题参考答案docWord下载.docx

A.true,trueB.false,falseC.true,falseD.false,true

5.以下关于AWT与Swing之间关系的叙述,正确的是()

A.Swing是AWT的提高和扩展

B.在写GUI程序时,AWT和Swing不能同时使用

C.AWT和Swing在不同的平台上都有相同的表示

D.AWT中的类是从Swing继承的

6.在以下Swing组件中,能为它指定布局管理器的是()

A.JScrollBar对象B.JMenuBar对象

C.JComboBox对象D.JDialog对象

7.一般的绘图程序要定义一个JPanel子类。

在JPanel子类中还要重定义一个方法,在这个方法中调用绘图方法,绘制各种图形。

要重定义的方法是()

A.paint()B.paintComponent()

C.repaint()D.update()

8.用Runnable接口实现多线程的主要工作是()

A.声明实现Runnable接口的类,在类内实现run()方法,让线程调用start()方法。

B.声明实现Runnable接口的类,在类内实现run()方法,在类内声明线程对象,在init()方法中创建新线程,启动新线程。

C.声明实现Runnable接口的类,在类内实现run()方法,在类内声明线程对象,在Init()方法或start()方法中创建新线程,在start()方法中启动新线程。

D.声明实现Runnable接口的类,在类内实现run()方法,在init()方法中创建新线程,在start()方法中启动新线程。

9.程序如果要按行输入输出文件的字符流,最合理的方法是采用()

A.BufferedReader类和BufferedWriter类

B.InputStream类和OutputStream类

C.FileReader类和FileWriter类

D.File_Reader类和File_Writer类

10.在编写访问数据库的Java程序中,要用到DriverManager类。

该类的作用是()

A.存储查询结果

B.处理与数据库的连接

C.在指定的连接中处理SQL语句

D.处理驱动程序的加载和建立数据库连接

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

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

错填、不填均无分。

11.Java程序的字节码文件的扩展名是__.class__。

12.构造一个Java表达式:

y/x>

5,并且x!

=0。

这个表达式是___y/x>

5&

&

x!

=0__。

13.在类声明之前用__final__修饰,声明类是不能被再继承的类,即它不能再有子类。

14.设有字符串定义:

Strings="

ABCDABCD"

则表达式s.indexOf("

B"

)的值是__1__。

15.在实现接口ActionListener的方法actionPerformed()中,常用的有两个获得事件源的方法,它们是getActionCommand()和__getSource()__。

16.使用单选按钮的方法是将一些单选按钮用_ButtonGroup_对象分组,使同一组内的单选按钮只允许一个被选中。

17.在Java语言中,用类Font对象设置字型。

如果要设置的字型是:

细明体、正常风格(Font.PLAIN),12磅字号,构造这样要求的Font对象fnA的代码是__FontfnA=newFont(“细明体”,Font.PLAIN,12)__。

18.线程从阻塞状态恢复到就绪状态,有三种途径:

自动恢复、用resume()方法恢复和用_notify()或notifyAll()__方法恢复。

19.为普通的8位字节流文件读和写操作提供支持的类是_FileInputStream和FileOutputStream_。

20.Connection类是java.sql包中用于处理与数据库连接的类。

Connection对象是用来表示__与特定数据库建立连接__的对象,Java程序对数据库的操作都在这种对象上进行。

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

21.请写出表示year年是闰年的Java表达式。

闰年的条件是:

每4年一个闰年,但每100年少一个闰年,每400年又增加一个闰年。

(year%4==0&

year%100!

=0||year%400==0)?

”闰年”:

”不闰年”

22.请写出在类的方法的定义之前,加上修饰字public、private的区别。

public修饰的方法没有限制访问权限,其他类的方法都能访问

private修饰的方法设置最强的访问权限,其他类的方法都不能访问

23.请写出将文本区text放置于滚动面板jsp,并将滚动面板jsp添加到JFrame窗口myFrame的Java语句。

JTextAreatext=newJTextArea(20,30);

JScrollPanejsp=newJScrollPane(text);

myFrame.add(jsp);

//myFrame.getContentPane().add(jsp);

24.要用Graphics2D类的方法画一个图形,首先要把参数对象g强制转换成Graphics2D对象;

然后,用图形类提供的静态方法Double()创建一个图形对象;

最后,以图形对象为参数调用Graphics2D对象的draw()方法绘制这个图形。

请写出用这样的方法绘制一条线段的程序段,线段的两个端点分别是(10.0,10.0)和(30.0,30.0)。

Graphics2Dg2d=(Graphics2D)g;

Line2Dline=newLine2D.Double(10.0,10.0,30.0,30.0);

g2d.draw(line);

25.请写出字符流数据与字节流数据的区别。

字符流数据是占16位的Unicode字符,由Reader和Writer类为字符流提供API和部分实现。

字节流数据是占8位的字节,用于读写二进制数据,比如图像和声音文件等。

26.请写出URLConnection类在编写Java网络应用程序中的作用。

URLConnection类在Java网络应用程序中,主要用于接收和发送信息。

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

27.方法intsigmaDigit(intn)的功能是求出十进制整数n的各位数字之和。

例如,n=1234,该方法的返回值是10。

staticintsigmaDigit(intn)

{intsum=0,d;

while(n>

0){

d=n%10;

_sum=sum+d__;

n/=10;

__returnsum__;

28.以下小应用程序能响应鼠标按动的事件,当鼠标在正文区的某个位置被点击时,就在该位置显示一个记号“×

”,程序限制最多保留最新20个位置。

importjava.applet.*;

importjava.awt.*;

importjavax.swing.*;

importjava.awt.event.*;

classMyPanelextendsJPanel{

publicvoidprint(Graphicsg,intx,inty)(

g.setColor(Color.red);

g.drawLine(x-5,y-5,x+5,y+5);

g.drawLine(x+5,y-5,x-5,y+5);

classMyWindowextendsJFrameimplementsMouseListener{

finalintMaxMarks=20;

intcurrentMarks=0,markCount=0;

Pointmarks[]=newPoint[MaxMarks];

MyPanelpanel;

MyWindow(){

this.setLocation(100,100);

this.setSize(300,300);

Containercon=this.getContentPane();

panel=newMyPanel();

con.add(panel);

__panel.addMouseListener_(this);

this.setVisible(true);

publicvoidpaint(Graphicsg){

inti;

g.clearRect(0,0,this.getWidth(),this.getHeight());

for(i=0;

i<

markCount;

i++){

__panel.print__(g,marks[i].x,marks[i].y);

publicvoidmousePressed(MouseEvente){}

publicvoidmouseReleased(MouseEvente){}

publicvoidmouseEntered(MouseEvente){}

publicvoidmouseExited(MouseEvente){}

publicvoidmouseClicked(MouseEvente){

marks[currentMarks]=newPoint(e.getX(),e.getY());

if(markCount<

MaxMarks)markCount++;

currentMarks=(currentMarks+1)%MaxMarks;

repaint();

publicclassClass1extendsApplet{

publicvoidinit(){

MyWindowmyWndow=newMyWindow();

}

29.这是一个处理选择项目事件的子窗口类。

窗口中有2个选择框,当选中某个选择框时,文本框将显示选择框对应的信息。

classMyWindowextendsJFrameimplementsItemListener{

JTextFieldtext;

JCheckBoxboxl,box2;

MyWindow(Strings){

__super(s)_;

this.setSize(400,200);

text=newJTextField(10);

box1=newJCheckBox("

A计算机"

false);

box2=newJCheckBox("

B计算机"

con.setLayout(newGridLayout(3,2));

con.add(newJLabel("

计算机产品介绍"

JLabel.CENTER));

add(newJLabel("

计算机2选1"

con.add(box1);

con.add(box2);

con.add(text);

box1.addItemListener(this);

box2.addItemListener(this);

this.pack();

publicvoiditemStateChanged(_ItemEvent__e){

if(e.getItemSelectable()==box1){

text.setText("

A公司生产"

}elseif(e.getItemSelectable()==box2){

B公司生产"

30.这是一个播放幻灯片的小应用程序中的paint()方法。

设幻灯片已由小应用程序的init()方法装入内存,并存放于myImage数组中,幻灯片的张数放于变量num中,paint()方法要播放的幻灯片号是currentImage。

intcurrentImage=0;

finalintnum=30;

Image[]myImage=new_Image_[num];

……

publicvoidpaint(Graphicsg){

if((mylmage[currentImage])!

=null)

g._drawImage_(myImage[currentImage],10,10,

myImage[currentImage].getWidth(this),

myImage[currentImage].getHeight(this),this);

31.以下定义的类ShareData用于管理多个线程共享数据val。

为了保证对共享数据val修改的完整性,线程对val的操作需要互斥,类ShareData中定义的方法modiData()就是供共享val的线程修改val的方法。

程序共有20个线程共享val,有些减少val,有些增加val。

publicclassClass1{

publicstaticvoidmain(Stringargs[]){

ShareDatamrc=newShareData(50);

Thread[]aThreadArray=newThread[20];

System.out.println("

\t刚开始的值是:

"

+mrc.getVal());

\t多个线程正在工作,请稍等!

for(inti=0;

i<

20;

intd=i%2==0?

50:

-30;

aThreadArray[i]=newThread(newMyMultiThreadClass(mrc,d));

aThreadArray[i].start();

WhileLoop:

//等待所有线程结束

while(true){

i++)

if(aThreadArray[i].__isAlive__())continueWhileLoop;

break;

\t最后的结果是:

"

}

classMyMultiThreadClassimplementsRunnable{

ShareDataUseInteger;

intdelta;

MyMultiThreadClass(ShareDatamrc,intd){

UseInteger=mrc;

delta=d;

publicvoidrun(){

1000;

UseInteger.modiData(delta);

try{Thread.sleep(10);

//做一些其他的处理

}catch(InterruptedExceptione){}

classShareData{

intval;

ShareData(intinitValue){val=initValue;

intgetVal(){returnval;

privatevoidputVal(intv){val=v;

_synchronized_voidmodiData(intd){

putVal(getVal()+d);

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

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

classA{

intx,y;

A(inta,intb){

x=a;

y=b;

publicclasssample{

publicstaticvoidmain(Stringargs[]){

Apl,p2;

p2=newA(12,15);

p1=p2;

p2.x++;

p1.x="

+p1.x);

p1.x=13

33.阅读下列程序,请写出调用pascal(4)的输出结果。

staticvoidpascal(intn){

intpas[];

pas=newint[n];

pas[0]=1;

System.out.println(pas[0]);

for(inti=2;

=n;

/*由存储在pas中的原来内容生成新内容*/

pas[i-l]=1;

for(intj=i-2;

j>

0;

j--)

pas[j]=pas[j]+pas[j-1];

for(intj=0;

j<

i;

j++)

System.out.print(pas[j]+"

System.out.println();

1

11

121

1331

34.阅读下列程序,请用示意图画出程序运行时呈现的界面。

importjava.awt*;

JButtonbutton;

JLabellabel;

MyPanel(Strings1,Strings2){

this.setLayout(newGridLayout(2,2));

button=newJButton(s1);

label=newJLabel(s2,JLabel.CENTER);

add(button);

add(label);

add(newJLabel());

JFramemw=newJFrame("

一个示意窗口"

mw.setSize(400,250);

Containercon=mw.getContentPane();

con.setLayout(newBorderLayout());

MyPanelpanel1,panel2;

panel1=newMyPanel("

按钮1"

"

标签1"

panel2=newMyPanel("

按钮2"

"

标签2"

JButtonbutton=newJButton("

开始按钮"

con.add(panel1,"

North"

con.add(panel2,"

South"

con.add(button,"

Center"

mw.setVisible(true);

35.阅读下列程序,请回答以下问题:

(1)程序要求在文本框text中输入的内容是什么?

一个网络资源的IP地址或域名

(2)辅助文本区showArea组件的作用是什么?

显示从网络上读取的资源信息

(3)如何使程序开始下载网络文本文件?

当点击“下载”按钮时开始下载网络文本文件

(4)程序采用什么输入方式下载网络文件?

采用缓冲式输入的方式下载网络文件

import.*;

importjava.awt.*;

importjava.awt.event.*;

import,java.io.*;

importjavax.swing.*;

publicclassClass1{

publicstaticvoidmain(Stringargs[]).

{newConnectNet("

读取网络文本文件示意程序"

classConnectNetextendsJFrameimplementsActionListener{

JTextFieldtext=newJTextField(30);

JTextAreashowArea=newJTextArea();

JButtonb=newJButton("

下载"

JPanelp=newJPanel();

ConnectNet(Strings){

super(s);

Containercon=this.getContentPane();

p.add(text);

p.add(b);

JScrollPanejsp=newJScrollPane(showArea);

b.addActionListener(this);

con.add(p,"

con.add(jsp,"

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setSize(500,400);

setVisible(true);

publicvoidactionPerformed(ActionEvente){

StringurlName=text.getText();

try{URLurl=newURL(urlName);

//由网址创建URL对象

URLConnectiontc=url.o

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

当前位置:首页 > 经管营销 > 经济市场

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2