Java復(fù)習(xí)參考題_第1頁(yè)
Java復(fù)習(xí)參考題_第2頁(yè)
Java復(fù)習(xí)參考題_第3頁(yè)
Java復(fù)習(xí)參考題_第4頁(yè)
Java復(fù)習(xí)參考題_第5頁(yè)
已閱讀5頁(yè),還剩10頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、Java復(fù)習(xí)參考題說(shuō)明:這是互聯(lián)網(wǎng)1班的機(jī)密文檔,不要隨意外傳,這里面的內(nèi)容可能有些錯(cuò)誤的,歡迎各位對(duì)這個(gè)文檔進(jìn)行修改,編程題有更好的方法的,也可以進(jìn)行修改的了。最后成為完美的。這份文檔僅供學(xué)習(xí)參考,不要只記答案,把原理搞明白啊。一些解釋和填代碼為藍(lán)色或紅色字體,希望好好看看,如果有修改的,在群里說(shuō)或者自己發(fā)個(gè)修正版文檔。題型及分?jǐn)?shù):?jiǎn)雾?xiàng)選擇題 (每小題2分,共30分)程序填空(每題5分,共20分)閱讀程序(每小題10分,共20分)編程題(每小題10分,共30分)一、 選擇題1、JAVA中提供了多種布局對(duì)象類。其中使用卡片式布局的是(D)。A.FlowLayout (流式布局) B.Boede

2、rLayout (圍界布局 頂層容器默的) C.BoxLayout (盒子布局 是swing的) D.CardLayout(卡片布局)補(bǔ)充:GridLayout(網(wǎng)格布局)2、Swing與AWT的區(qū)別不包括 (D)。A.Swing是由純Java實(shí)現(xiàn)的輕量級(jí)構(gòu)件 B.Swing沒(méi)有本地代碼 C.Swing不依賴操作系統(tǒng)的支持 D.Swing支持圖形用戶界面 (都是支持的)3、下列哪個(gè)選項(xiàng)是創(chuàng)建一個(gè)標(biāo)識(shí)有關(guān)閉按鈕的語(yǔ)句?(C)A.JTextField b = new JtextField(關(guān)閉); (文本框)B.JTextArea b = new JTextArea(關(guān)閉); (文本域)C.JBu

3、tton b = new Jbutton(關(guān)閉); (按鈕)D.JCheckbox b = new Jcheckbox(關(guān)閉); (復(fù)選框) 補(bǔ)充:JPasswordField(口令輸入域)、JLabel(標(biāo)簽) 、JComboBox(組合框)JList(列表框) 、JTable(表格) 、JMenu(菜單)、JDialog(對(duì)話框)JOptionPane(標(biāo)準(zhǔn)對(duì)話框)、JFileChooser(文件對(duì)話框)4、鼠標(biāo)事件的監(jiān)聽(tīng)器接口MouseListener能實(shí)現(xiàn)的事件不包括(D)。A.按下B.釋放C.點(diǎn)擊D.拖動(dòng)補(bǔ)充:還有的是進(jìn)入和離開(kāi)事件窗口事件包括:關(guān)閉窗體、窗體失去焦點(diǎn)、獲得焦點(diǎn)、最小

4、化等 鍵盤事件包括:按下鍵盤按鍵、放開(kāi)鍵盤按鍵、敲擊鍵盤按鍵5、每個(gè)使用Swing組件的程序必須至少有一個(gè)(B)。A. 按鈕B. 頂層容器C. 標(biāo)簽D. 菜單6、在Java中,而無(wú)需在程序中用import導(dǎo)入的包是(D)。Ajava.applet Bjava.awtCjava.util DJava.lang (默認(rèn)的)7、類Panel默認(rèn)的布局管理器是(C)。 AGridLayout BBorderLayout(頂層容器默認(rèn)的)CFlowLayout (Panel面板默認(rèn)的) DCardLayout8、java中用于創(chuàng)建文件對(duì)象的類是(A)。AFile (文件) B. Object (對(duì)象)

5、C. Thread (線程) D. Frame (框架)9、下列描述中,正確的是(C)。A在Serializable接口中定義了抽象方法B在Serializable接口中定義了常量 C在Serializable接口中沒(méi)有定義抽象方法,也沒(méi)有定義常量 D在Serializable接口中定義了成員方法 10、在讀文件a.dat 時(shí),能使用該文件名作為參數(shù)進(jìn)行實(shí)例化的類是(D)。ABufferedReader BufferedReader(Reader in)BDataInputStream DataInputStream(InputStream in)CDataOutputStream DataO

6、utputStream(OutputStream out)DFileInputStream FileInputStream(File file)11、凡是從中央處理器流向外部設(shè)備的數(shù)據(jù)流稱為( D )。 A文件流 B字符流 C輸入流 D輸出流12、當(dāng)線程被創(chuàng)建后,調(diào)用start()方法之前,其所處的狀態(tài)是(C)。 A阻塞狀態(tài) B運(yùn)行狀態(tài) (run) C就緒狀態(tài) D新建狀態(tài)(new)13、下面哪個(gè)關(guān)鍵字可以對(duì)對(duì)象加互斥鎖。(A)Asynchronized Btransient Cserialize Dstatic14、為了得到當(dāng)前正在運(yùn)行的線程,可使用下列哪個(gè)方法?(B)。AgetName()

7、(獲得名字)BThread.CurrentThread().Bsleep() (睡眠) Drun() (運(yùn)行)15、ServerSocket的監(jiān)聽(tīng)方法accept()的返回值類型是(C) Avoid BObject CSocket DDatagramSocket16、當(dāng)使用客戶端套接字Socket創(chuàng)建對(duì)象時(shí),需要指定(A) A服務(wù)器主機(jī)名稱和端口 B服務(wù)器端口和文件 C服務(wù)器名稱和文件 D服務(wù)器地址和文件17、若要取得數(shù)據(jù)包的中源地址,可使用下列哪個(gè)方法?(A) AgetAddress() BgetPort() CgetName() (源文件名)DgetData() (日期)18、程序與數(shù)據(jù)庫(kù)

8、連接后,需要查看某個(gè)表中的數(shù)據(jù),使用下列哪個(gè)語(yǔ)句?(A)AexecuteQuery();(記錄查詢)BexecuteUpdate(); (記錄操作)CexecuteEdit(); DexecuteSelect(); 二、程序填空1下面程序?qū)崿F(xiàn)如下界面:import java.awt.*;class Qualification extends Frame Checkbox t1=new Checkbox(Visual Basic); Checkbox t2=new Checkbox(Visual C+); Checkbox t3=new Checkbox(Java); CheckboxGroup

9、 cg = new CheckboxGroup(); /復(fù)選框的組 Checkbox r1=new Checkbox(專科,cg,false); Checkbox r2=new Checkbox(本科,cg,false); Checkbox r3=new Checkbox(碩士,cg,false); Checkbox r4=new Checkbox(博士,cg,false); Label lb1=new Label(您的學(xué)歷為: ); Label lb2=new Label(您精通的語(yǔ)言為: ); public Qualification(String s ) super(s); setLay

10、out(new GridLayout(10, 1); /設(shè)置為網(wǎng)格布局10行一列 add(lb1);add(r1);add(r2);add(r3);add(r4);add(lb2);add(t1);add(t2);add(t3); public static void main(String args) Qualification q=new Qualification(學(xué)識(shí)!); /new 一個(gè)新對(duì)象q 標(biāo)題是“學(xué)識(shí)!” q.setSize(400,250); q.show( ); 補(bǔ)充:這個(gè)程序主要是圖形界面的基礎(chǔ),知道一些布局,知道一些組件使用方法,這些就差不多了。這個(gè)程序有點(diǎn)問(wèn)題。程序

11、網(wǎng)上地址:2下面程序從mytest.txt文件中讀取字符,將讀到的文字列在TextArea里面。import java.awt.*;import java.io.*;public class BufferedReaderTest extends Frame public static void main(String args) String str; BufferedReaderTest test=new BufferedReaderTest(); TextArea ta=new TextArea(); try /建立一個(gè)BufferedReader流讀取文件 BufferedReader

12、breader=new BufferedReader(new FileReader(mytext.txt); /對(duì)象要是文件 while(true) str=breader.readLine(); /讀取一行文字 if(str=null) /讀到文件結(jié)尾 break; ta.append(str+n); /將讀到的文字列在TextArea里面 catch(IOException e) /捕獲是否為文件未找到異常 test.add(ta,BorderLayout.CENTER); test.setSize(500,200); test.setVisible(true); /這是一道IO流的題目,

13、要注意一些流的基本語(yǔ)法,而且要記住捕獲的是IO異常3下面程序?qū)崿F(xiàn)了文件拷貝功能,從file1.txt 把文字復(fù)制到file2.txt。import java.io.*;public class filestream public static void main(String args) try File inFile=new File(file1.txt); /源文件 File outFile=new File(file2.txt);/新文件 FileInputStream fis=new FileInputStream(inFile); FileOutputStream fos=new F

14、ileOutputStream(outFile); int c; while(c=fis.read()!=-1) fos.write(c); /新文件時(shí)寫的,源文件是讀的 fis.close(); fos.close(); catch(FileNotFoundException e) System.out.println(FileStreamsTest: +e); catch(IOException e) System.err.println(FileStreamsTest: +e);注意:文件讀寫流要注意,源文件是用來(lái)讀(read)的,新文件用來(lái)寫(write)的,不要弄錯(cuò)的了。4下面程序使

15、用Swing設(shè)計(jì)一個(gè)窗口,窗口標(biāo)題是“HelloSwing”,窗口包含一個(gè)標(biāo)簽“你好,Swing”。import javax.swing.*; public class HelloSwing public static void main(String args) JFrame frame = new JFrame(“HelloSwing”); /這個(gè)是窗體 JLabel label = new JLabel(“你好,Swing”); /這個(gè)是標(biāo)簽 frame.getContentPane().add(label); frame.setDefaultCloseOperation(JFrame.

16、EXIT_ON_CLOSE); frame.setSize(300,200); /設(shè)置窗體大小 frame.setVisible(true); 三、讀程序?qū)懡Y(jié)果1、import java.io.*; public class CharInput public static void main(String args) throws java.io.IOException String s; inputStreamReader ir; BufferedReader in; ir=new inputStreamReader(System.io); in=new BufferedReader ir)

17、; while (s=in. readLine()!=null) System.out.println(“Read;”+s); 輸出結(jié)果為:Read:+(s的內(nèi)容,就是鍵盤輸入的)2、import java.io.*; import java.util.Date; public class UnSerializeDate UnSerializeDate() Date d=null; try FileInputStream f=newFileInputStream (“date.ser”); ObjectInputStream s=new ObjectInputStream(f); d=(Dat

18、e) s.readObject(); f.close(); catch(Exception e) e.printStackTrace(); System.out.println(“Unserialized Date object from date.set”); System.out.println(“Date:”+d); public static void main(String args) new UnSerializeDate(); 結(jié)果:會(huì)把date.ser文件里的內(nèi)容讀出來(lái) 補(bǔ)充:這個(gè)程序如何傳參的:這個(gè)程序中main方法中沒(méi)有傳參數(shù)。而FileInputStream f = ne

19、w FileInputStream (date.ser);在構(gòu)造的時(shí)候,其中參數(shù)date.ser是與這個(gè)程序在同一個(gè)目錄下的一個(gè)文件的名字。這樣就可以通過(guò) f 來(lái)讀這個(gè)文件中的內(nèi)容。而ObjectInputStream s = new ObjectInputStream (f); 這個(gè)是對(duì)象的反序列化,就是可以把一“序列化”到文件中的對(duì)象讀出來(lái)。四、程序設(shè)計(jì)1、編寫一個(gè)Java程序?qū)崿F(xiàn)多線程,在線程中輸出線程的名字,隔300毫秒輸出一次,共輸出20次。源代碼:public class si1 extends Threadpublic static void main(String args)

20、Thread si = new Thread20; /線程創(chuàng)建 for(int i = 0; i 20; i+) /為了次數(shù)的限制sii = new Thread(); sii.start(); /線程就緒 System.out.println(sii.getName(); System.out.println(線程睡眠300毫秒); try Thread.sleep(300); /線程睡眠 catch (InterruptedException e) / TODO 自動(dòng)生成的 catch 塊e.printStackTrace(); 2. 編寫程序,在屏幕上顯示帶標(biāo)題的窗口,并添加一個(gè)按鈕。當(dāng)

21、用戶單擊按鈕時(shí),結(jié)束程序。源代碼:import java.awt.*;import java.awt.event.*;import javax.swing.*;public class si2 private JFrame loginFrame = null; private JPanel loginPanel = null; private JPanel buttonPanel = null; private JButton submit = null; private void init() loginFrame = new JFrame(退出); loginPanel = new JPa

22、nel(); buttonPanel = new JPanel(); submit = new JButton(退出); loginFrame.setLayout(new GridLayout(3,1); loginFrame.add(buttonPanel); buttonPanel.add(submit); submit.addActionListener(new ButtonListener(); loginFrame.pack(); loginFrame.setLocation(400, 300); loginFrame.setSize(500,300); loginFrame.set

23、Visible(true); loginFrame.setAlwaysOnTop(true); private class ButtonListener implements ActionListener /監(jiān)聽(tīng)按鈕的 public void actionPerformed(ActionEvent event) String command = event.getActionCommand(); if(退出.equals(command) System.exit(0); public static void main(String args) new si2().init(); 3 編寫程序?qū)?/p>

24、現(xiàn)窗口,包含一個(gè)標(biāo)簽、一個(gè)文本框和一個(gè)按鈕,當(dāng)用戶單擊按鈕時(shí),程序把文本框中的內(nèi)容復(fù)制到標(biāo)簽中。源代碼:import java.awt.*;import java.awt.event.*;import javax.swing.*;public class si3 private JFrame loginFrame = null; private JPanel loginPanel = null; private JPanel wenziPanel = null; private JPanel biaoPanel = null; private JPanel buttonPanel = null

25、; private JTextField wenziField = null; private JLabel wenziLabel = null; private JButton submit = null; private void init() loginFrame = new JFrame(復(fù)制界面); loginPanel = new JPanel(); wenziPanel = new JPanel(); biaoPanel = new JPanel(); buttonPanel = new JPanel(); wenziField = new JTextField(15); wen

26、ziLabel = new JLabel(準(zhǔn)備復(fù)制); submit = new JButton(復(fù)制); loginFrame.setLayout(new GridLayout(3,1); loginFrame.add(wenziPanel); loginFrame.add(biaoPanel); loginFrame.add(buttonPanel); biaoPanel.add(wenziLabel); wenziPanel.add(wenziField); buttonPanel.add(submit); submit.addActionListener(new ButtonListe

27、ner(); loginFrame.pack(); loginFrame.setLocation(400, 300); loginFrame.setSize(500,300); loginFrame.setVisible(true); loginFrame.setAlwaysOnTop(true); private class ButtonListener implements ActionListener public void actionPerformed(ActionEvent event) String command = event.getActionCommand(); Stri

28、ng str= wenziField.getText(); if(復(fù)制.equals(command) wenziLabel.setText(str); public static void main(String arg) new si3().init(); 4 使用Socket技術(shù),編寫服務(wù)器端和客戶端程序,實(shí)現(xiàn)服務(wù)器端和客戶端的通信。服務(wù)器端接受客戶端發(fā)送來(lái)的信息并回顯,直到客戶端發(fā)送結(jié)束標(biāo)記END;客戶端向服務(wù)器發(fā)送信息,并接受服務(wù)器端返回來(lái)的消息,并且回顯。源代碼: 客戶端:import java.io.*;import .*;import java.util.*;public cl

29、ass SocketClientTest public static void main(String args) try Socket clientSocket = new Socket(localhost, 1688); InputStream inData = clientSocket.getInputStream(); OutputStream outData = clientSocket.getOutputStream(); PrintWriter toServer = new PrintWriter(outData, true); Scanner sc = new Scanner(System.in); Scanner data = new Scanner(inData); String heading = data.nextLine(); System.out.println(heading); while (sc.hasNextLine() String line =

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論