Q3. the Class Streamtokenizer Is Used to Read Byte Data. True Or False?

Total Page:16

File Type:pdf, Size:1020Kb

Q3. the Class Streamtokenizer Is Used to Read Byte Data. True Or False?

Review

Q1. Exceptions identify errors that arise in your program. Name the two categories of exceptions that are derived directly from Throwable and differentiate between them.

Q2 True or false. The classes InputStream and OutputStream are used to read and write byte data.

Q3. The class StreamTokenizer is used to read byte data. True or false?

Q.4 The classes Reader and Writer are used to read and write character data. True or false?

Q5 Write down the output as it would appear on the screen. class Exceptions { public static void main(String[] args) { int x[] = {2, 4, 6}; method(0, x); method(x[2], x); method(2, x); }

static void method(int i, int arr[]) { String str = "Yes its true"; try { System.out.println("Programming II"); System.out.println("This first value is " + arr[i]); System.out.println("This second value is " + arr[i]/(arr[i] - 6)); System.out.println("This line will be printed"); } catch(ArithmeticException e) { System.out.println("ArithemticException caught"); } catch(ArrayIndexOutOfBoundsException e) { System.out.println("ArrayIndexOutOfBoundsException caught"); } finally { System.out.println(str); } } 1 }

Q16 Given the following incomplete class definition, write appropriate Java code that will use the string str to create a file object. [1 mark]

class myFile { File f; myFile(String str) {

} }

Q7 Given the following method declaration, write appropriate code that will retrieve the number of bytes in the file.

int getBytes(File f) {

}

Q8 Given the following incomplete method, write appropriate Java code to that will use the string variable str to: (i) Create a BufferedReader object.

(ii) Use the BufferedReader object created in part (i) to read the file until it is empty. void readFile(String str) {

}

Q9 Use the concept of stack to convert the following infix expression to postfix expression.

5 * 2 + ( 14 – 12 ) – 10 * 6 The stack must be used to hold the operators and the left parentheses. The postfix string is used to hold the postfix string (the output). Show the state of the stack and the postfix string after each item is read from the infix string. The first two are done for you. The first four entries are done for you.

Question3 Use the concept of stack to evaluate the following postfix expression. Use the buckets below to show the state of the stack at each stage of the evaluation.

5 3 2 * + 4 - 5 +

2

Recommended publications