1. Drag the drop text into the empty boxes to best complete the following paragraph.

A steam represents a flow of data from a _____________ to a ________________. There are streams for input and for output, and they can deal with data in terms of bytes or character. We normally use the ________________ class when reading in the text entered at the keyboard or held in a file, but for non-character (i.e byte) data held in a file is best done using _______________          whereas non-character data would be written to a file using __________________.

 

2.  Study the following code.

Public class main {public static void main (string [] args) throws Exception//1

{Qq = new Q();

q.MyMethod(“”); //2

q.myMethod(“a”); //3

q.myMthod(“abc”);//4

q.myMethod(null); //5}}

public class Q

{public void myMethod (string s) throws Expection

{try{system.out.printIn(“The first character is “+s.chartAt(1));}

Catch ( Exception e)

{system.out.printIn(“exception thrown”);}

Finally {system.out.printIn(“finally”);}}}

Assuming the correct imports have been made, select only those options below that are correct.

 

 

3. Select only those options below that are correct statement.

 

4. Assume that the following code is part of a public instance method.

The file “data.txt” exits, is in the correct folder and contains a sequence of int values only, each on a new line.

Scanner scan = new scammer (new file(“data.txt”)); //1

Int variable = 0;

Int in;

While (scan.hasNext() ) //2}

In = scan.nextInt(); //3

Variable = variable + in;}

System.out.printIn(“variable is “ + variable); scan.close(); //4

Select only those options below that are true.

 

5. Give the following method which compiles successfully, the data file “ data.txt” which contains a number of strings, one per line, and assuming all required imports, select the options that are correct.

 

6. Study the code fragment below and then select only those options that are correct statements.

You can assume that all code compiles and that all possible exceptions are propagated.

FileOutoutStream fout = new

Fileoutputstream (“data.dat”); //1

DataOutputStream Dout = new DataOutputStream (Fout): //2

Dout.writeByte(66); //3

Dout.writeChar (66); //4

Dout.write (66); //5

fileInputStream fin = new FileInputStream(“data.dat”); //6

DataInputStream din = new DataInputStream(fin); //7

Byte b = din. readByte(); //8

Char c = din.read() ; //9

Int i = din.read() //10

System.out.printIn(“byte was” + b + “ char was” + C + o” int was” + i);

 

 

7. What single word best describes this; “The keyword used to indicate that a method will propagate an exception”.

Be very careful to spell your single word correctly. No marks will be awarded for an incorrectly spelt keyword. Do not insert spaces (or any other characters) before or after it.

 

    

    • 12 years ago
    A+ Answers
    NOT RATED

    Purchase the answer to view it

    • drag_the_drop_text.doc