( 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 【 11 】 (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; i50000; i++){os.write(1);}}os.close();return(int)(()new Date()).getTime() - then.getTime());}

( 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 【 11 】 (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());

}


相关考题:

【说明】下面是一个Applet程序,程序的功能是在显示面板上输出字符串。当html页面被其他窗口遮挡后再次显示时,请给出输出结果。import java.awt.*;import java. (1). *;public class MyApplet (2) Applet {public void (3) (Graphics g) {g.drawString(tip,20,40);tip ="I am Java Applet";}public void init() {tip ="welcome"; }private (4) tip;}<html><head><title> A Simple Applet </title></head><body><applet code="MyApplet.class" width=800 height=400></applet></body></html>网页输出 (5)

定义JavaApplet 程序时,必须有的import 语句是( )。A.import java. applet. Applet;B.import java. io.*;C.import java. awt. event;D.import java. Lang.*;

下列Java源程序结构中前三种语句的次序,正确的是A.import, package, public classB.import必为首,其他不限C.public class, import, packageD.package, import, public class

下列Applet在坐标 ( 20,20) 处显示一幅GIF图像,在横线处填入正确的语句。import java. net.*;import java. awt.*;import java. applet.*;public class Test extends Applet {Image IMG;public void init() {URL url = getDocumentBase ();String name="IMG.gif";【 】}public void paint(Graphics g) {g. drawImage ( IMG,20,20,this);}}

下列程序构造了一个 Swing Applet ,请在下划线处填入正确的代码Import javax.swing.*;Import java.awt.*;Public class SwingApplet extends 【 13 】 {Jlabel l = new Jlabel ( “ This is a Swing Applet. ” );Public void init(){Container contentPane = getContentPane();contentPane.add(1);}}

下列哪个选项的java源文件代码片段是不正确的?A.package testpackage; public class Test{ }B.import java. io. *; package testpaekage; public class Test { }C.import java.io.*; class Person { } public class Test { }D.import java.io.*; import java. awt.*; public class Test{ }

请将下面的Applet程序补充完整。import java. awt. *;import java. applet. *;public class Hi【 】{public void paint(Graphics g){g. drawString("Hi!", 25, 25);}}

阅读下面Applet程序 import javax. swing. *; import java. awt. *; public class SwintgApplet extends JApplet{ JLabel 1=new JLabel("This is a Swing Applet."); public void init(){ ________________________________ } } 在程序下画线处填入正确的选项是A.Container contentPane=getContenPane(); cotentPane. add(1);B.JPanel comtenPane=new Jpane(); contentPane. add(1);C.contentPane. add(1);D.add(1);

选择正确的语句填在下列程序的横线处,使程序正常运行。 package ch1; import java. io. *; import j ava. util. *; class C45 implements Seritizable ______Public Thread t = new Thread(new T45(), "t"); public intcnt = 0; public C45() { t. start ( ) class T45 implements Runnable public int[] a = new int[4]; public void run() { for(int i - 0; i < 4; i++) { a[i] - i +4; } } } public class ex45 { static String fileName = "ch1\\file45.txt"; public static void main(String[] args) throws Exception { C45 bj = new C45 (); FileOutputStream fos = new FileOutputStream(fileName); ObjectOutputStream os = new ObjectOutputStream(fos); oos. writeObject (obj); oos.clese (); fos.close (); System. out, println (obj . toString ( ) ); } }A.transientB.protectedC.packageD.final

阅读以下说明和Java以及HTML代码,将应填入(n)处的字句写在对应栏内。[说明]编写一个Applet程序,接受HTML文件传递的整数参数,根据该参数指定Applet中文本框的长度。编写对应的HTML文件运行这个Applet。[Java 代码]import java. applet.*;import java. awt.*;public class chuangdics extends (1){TextField tf=new TextField ();int tfLength=0;public void init(){try{tfLength=Integer. parseInt( (2) ("length"));tf. setColumns (tfLength);add (tf);}catch (NumberFormatException nfe){tf. (3) ("HTML 文件传人的参数格式错误。");add(tf);}}}[HTML 代码]<html><head><title>(4)</title></head><body><hr><applet code=chuangdics width=700 height=150><param name=length value=20>(5)<hr></body></htmI>

从对象流中读取对象,请在下面横线处填写代码完成此程序。import java.util. *;import java. io. *;public class UnSerializeDate{date d = null;UnSerializeDate ( ){try{FileInputStream f1 = new FileInputStream("date.ser");d = (Date) s. readobject ();f1,close();}catch (Exceptin e){e. printStackTrace ();}}public static main(String args [] ){System.out.println("The date read is: "+ a.d.toString());}}

阅读以下说明和Java代码,将解答写入对应栏内。【说明】请完成下列Java程序。程序的执行结果是生成一个具有一个TextField类型的对象in、 Button类型的对象btn和Label类型的对象out图形用户界面,程序的功能是计算用户输入数的平方,如图3所示。注意:请勿改动main()主方法和其他已有的语句内容,仅在下划线处填入适当的语句。【程序】import java. awt.*;import java, awt. event.*;public class square {public static void main(String args[ ]){(1)}}class AppFrame. extends Frame{TheAdapterTest listener = new TheAdapterTest( );Text Field in = new TextField (5);Button btn = new Button("计算");Label ut = new Label("用于显示计算结果");public AppFrame( ){setLayout( new FlowLayout( ));add(in);add(btn)add(out);btn. addActionListener( new BtnActionAdapter( ));addWindowListener (listener);setSize(400,100);show( );}class BtnActionAdapter implements (2) {public void actionPerformed((3)) {String s = in. getText( );double d =(4)double sq = d * d;out. setText(d+"的平方是:" +sq);}}class TheAdapterTest extends WindowAdapter{public void windowCIosing((5)){System. exit(1)}}}

下面关于Applet 的说法中正确的是( )。A.Applet 也需要main 方法B.Applet 可以继承自java. awt. AppletC.Applet 能访问本地文件D.Applet 程序不需要编译

下列哪个选项的java源文件程序段是不正确的? ( )A.package testpackage; public class Test{ }B.import java.io.*; package testpackage; public class Test{ }C.import java.i.*; class Person{} public class Test{ }D.import java.io.*; import java.awt.*; public class Test { }

下列Applet用于显示提供它的主机的IP地址。请选择正确的语句填入横线处。 import java.awt.*; import java. awt. event.*; import java.applet.Applet; import java.net. *; public class ex23 extends Applet { public void init() { setLayout(new GridLayout(2, 1); Button btm = new Button("显示IP"); final Label 1 = new Label(" "); btn. addActionListener (new ActionListener ( ) { public void actionPerformed(ActionEvent ae) { try { URL ur1 = getCodeBase(); String strName = ur1.getHost(); ______ 1.setText (ia.toString()); } catch (Exception e) { e.printStackTrace (); } } }); add (btn); } }A.InetAddress ia = URL.getByName(strName);B.InetAddress ia = InetAddress.getByName(strName);C.InetAddress ia = new InetAddress.getByName(strName);D.InetAddress ia = InetAddress.getByName(ur1);

下列程序将Date对象写入文件file42.txt中,选择正确的语句填入下列程序中的横线处。 package ch1; impbrt java. io. *; import java. util. *; public class ex42 { static String fileName = "ch1\\file42.txt"; static Date date = null; public static void main(String[] args) { date = new Date(); try { FileOutputStream fos = new FileOutputStream(file Name); ObjectOutStream os = new ObjectOutputStream(fos); oos.______; oos.close(); fos.close(); System.out.println(date.toString()); } catch(Exception e) { System.out.println(e.getMessage()); } } }A.writeObject()B.writeObject(date)C.write(date)D.writeByte(date)

下面程序的输出结果是( )。 import java. awt.*; import java. applet.*; public class HelloApplet extends Applet { public void paint(Graphics g) { g.drawString("Hello World! ",20,20); } }A.20,20B.Hello World!C.编译不能通过D.以上都不对

请在下划线处填入代码,使程序能够正确运行。import java .awt.*;import java .applet.*;public class SayHi extends Applet{public void【 】(Graphics g){g .drawString(“Hi!”20,20);}}

下列代码包括一个Html文件和一个Applet类。在hello. html文件的横线处填入相应内容,把HelloApplet嵌入在hello. html中。hello. html文件内容:<HTML><HEAD><TITLE>Hello</TITLE></HEAD><BODY><APPLET CODE="【 】"WIDTH=150 HEIGHT=25></APPLET></BODY></HTML>HelloApplet. java文件内容:import java. awt. *;import java. applet. *;public class HelloApplet extends Applet{public void paint(Graphics g){g. drawString("Hello!" ,25,25);}}

( 8 )在下列 Java applet 程序的横线处填入代码,使程序完整并能够正确运行。Import java. awt. *;Import java. applet. *;Public class Greeting extends applet{Public void 【 8 】 (Graphics g) {g.drawSting( “ how are you! ” ,10,10);}}

( 11 )下列程序的功能是统计命令行参数的个数,请在下划线处填上适当的代码。public class Length{public static void main(String args[]){System.out.println( " number of String args: " +args. 【 11 】 );}}

一个程序中,package、import、和class的排放次序是()A、package、import、classB、import、package、classC、三者任意D、class在最后,import、package排放次序任意

在单一文件中import、class和package的正确出现顺序是()A、package,import,classB、class,import,packageC、import,package,classD、package,class,import

下列有关类声明的代码片段,哪一项是正确的?() A、 import java.sql.*; package school; class Student{ }B、 package school; import java.sql.*; class Student{ }C、 package school; class Student{ } import java.sql.*;D、 package school; import java.sql.*;private String name; class Student{ }

单选题在单一文件中import、class和package的正确出现顺序是()Apackage,import,classBclass,import,packageCimport,package,classDpackage,class,import

单选题下列有关类声明的代码片段,哪一项是正确的?()A import java.sql.*; package school; class Student{ }B package school; import java.sql.*; class Student{ }C package school; class Student{ } import java.sql.*;D package school; import java.sql.*;private String name; class Student{ }

单选题一个程序中,package、import、和class的排放次序是()Apackage、import、classBimport、package、classC三者任意Dclass在最后,import、package排放次序任意