WOSO Source Code (Java)

Similar documents
Date: Dr. Essam Halim

Full download all chapters instantly please go to Solutions Manual, Test Bank site: testbanklive.com

Full file at

Object-Oriented Programming in the Java language

Exceptions and Working with Files

CIS 265/506 Exam1 Spring 2012 Prof. V. Matos Exam Last Name First Name:

IT101. File Input and Output

Full file at

Input, Output and Exceptions. COMS W1007 Introduction to Computer Science. Christopher Conway 24 June 2003

Java Input/Output. 11 April 2013 OSU CSE 1

Fundamentals of Object Oriented Programming

I pledge by honor that I will not discuss this exam with anyone until my instructor reviews the exam in the class.

I/O in Java I/O streams vs. Reader/Writer. HW#3 due today Reading Assignment: Java tutorial on Basic I/O

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Special error return Constructors do not have a return value What if method uses the full range of the return type?

CS115. Chapter 17 Exception Handling. Prof. Joe X. Zhou Department of Computer Science. To know what is exception and what is exception handling

Input-Output and Exception Handling

Java Errors and Exceptions. Because Murphy s Law never fails

Introduction Unit 4: Input, output and exceptions

Character Stream : It provides a convenient means for handling input and output of characters.

Training topic: OCPJP (Oracle certified professional Java programmer) or SCJP (Sun certified Java programmer) Content and Objectives

BBM 102 Introduction to Programming II Spring Exceptions

Full file at Chapter 2 - Inheritance and Exception Handling

Here is a hierarchy of classes to deal with Input and Output streams.

Midterm Examination (MTA)

Computer Programming, I. Laboratory Manual. Final Exam Solution

Exceptions Chapter 10. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

Chapter 12 Exception Handling

F1 A Java program. Ch 1 in PPIJ. Introduction to the course. The computer and its workings The algorithm concept

File IO. Computer Science and Engineering College of Engineering The Ohio State University. Lecture 20

Check out how to use the random number generator (introduced in section 4.11 of the text) to get a number between 1 and 6 to create the simulation.

CIS265 - Spring Exam 2 First Name Last Name CSU#

Section 2.2 Your First Program in Java: Printing a Line of Text

Chapter 2: Basic Elements of Java

Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Java Basics

What are Exceptions?

C17: File I/O and Exception Handling

Loops. CSE 114, Computer Science 1 Stony Brook University

Exception Handling in Java

Pace University. Fundamental Concepts of CS121 1

23 Error Handling What happens when a method is called? 23.1 What is Exception Handling? A.m() B.n() C.p()

CIS 265 Summer 2015 Exam 1 First Name Last Name

BBM 102 Introduction to Programming II Spring 2017

Exceptions and I/O: sections Introductory Programming. Errors in programs. Exceptions

Introductory Programming Exceptions and I/O: sections

The Java I/O System. Binary I/O streams (ASCII, 8 bits) The decorator design pattern Character I/O streams (Unicode, 16 bits)

Example: Copying the contents of a file

Agenda & Reading. Python Vs Java. COMPSCI 230 S Software Construction

Programming with Java

Darshan Institute of Engineering & Technology for Diploma Studies

Std 12 Lesson-10 Exception Handling in Java ( 1

09-1. CSE 143 Java GREAT IDEAS IN COMPUTER SCIENCE. Overview. Data Representation. Representation of Primitive Java Types. Input and Output.

Software Development & Education Center. Java Platform, Standard Edition 7 (JSE 7)

CS 251 Intermediate Programming Java I/O Streams

Lara Technologies Special-Six Test

Java in 21 minutes. Hello world. hello world. exceptions. basic data types. constructors. classes & objects I/O. program structure.

Sri Vidya College of Engineering & Technology Question Bank

Basic I/O - Stream. Java.io (stream based IO) Java.nio(Buffer and channel-based IO)

More on Exception Handling

For more details on SUN Certifications, visit

EXCEPTION HANDLING. // code that may throw an exception } catch (ExceptionType parametername) {

תוכנה 1 תרגול 8 קלט/פלט רובי בוים ומתי שמרת

Exceptions Handling Errors using Exceptions

CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O

CS244 Advanced Programming Applications

Interpreted vs Compiled. Java Compile. Classes, Objects, and Methods. Hello World 10/6/2016. Python Interpreted. Java Compiled

Chapter 10. IO Streams

Programming Languages and Techniques (CIS120)

Supplementary Test 1

Lecture 19 Programming Exceptions CSE11 Fall 2013

CS Week 11. Jim Williams, PhD

Chapter 2 ELEMENTARY PROGRAMMING

CSC 1214: Object-Oriented Programming

Lecture 11.1 I/O Streams

Index COPYRIGHTED MATERIAL

MSc/ICY Software Workshop Exception Handling, Assertions Scanner, Patterns File Input/Output

COE318 Lecture Notes Week 10 (Nov 7, 2011)

Introduction. Exceptions: An OO Way for Handling Errors. Common Runtime Errors. Error Handling. Without Error Handling Example 1

Object-Oriented Programming Design. Topic : Streams and Files

PIC 20A Streams and I/O

COMP 213. Advanced Object-oriented Programming. Lecture 19. Input/Output

1993: renamed "Java"; use in a browser instead of a microwave : Sun sues Microsoft multiple times over Java

More on Exception Handling

1. Java is a... language. A. moderate typed B. strogly typed C. weakly typed D. none of these. Answer: B

Recitation: Loop Jul 7, 2008

Java Bytecode (binary file)

Exception in thread "main" java.lang.arithmeticexception: / by zero at DefaultExceptionHandling.main(DefaultExceptionHandling.

Computer Science is...

Programming Languages and Techniques (CIS120)

CPSC 219 Extra review and solutions

needs to be reliable, easy to change, retarget efficiency is secondary implemented as interpreter, with virtual machine

CMSC 331 Second Midterm Exam

Lecture 22. Java Input/Output (I/O) Streams. Dr. Martin O Connor CA166


I/O Streams. program. Standard I/O. File I/O: Setting up streams from files. program. File I/O and Exceptions. Dr. Papalaskari 1

I/O Streams. program. Standard I/O. File I/O: Setting up streams from files. program. File I/O and Exceptions. Dr. Papalaskari 1

COE 212 Engineering Programming. Welcome to Exam II Monday May 13, 2013

Vendor: Oracle. Exam Code: 1Z Exam Name: Java SE 8 Programmer. Version: Demo

Software 1 with Java. Recitation No. 7 (Java IO) May 29,

Any serious Java programmers should use the APIs to develop Java programs Best practices of using APIs

Transcription:

WOSO 2017 - Source Code (Java) Q 1 - Which of the following is false about String? A. String is immutable. B. String can be created using new operator. C. String is a primary data type. D. None of the above. Q 2 - What is true about a final class? A. Class declared final is a final class. B. Final classes are created so the methods implemented by that class cannot be overridden. C. It can't be inherited. D. All of the above. Q 3 - This is the parent of Error and Exception classes. A. Throwable B. Catchable C. MainError D. MainException Q 4 - Can try statements be nested? A. True. B. False. Q 5- Which of the following is smallest integer data type? A. Long B. Int C. Short D. Byte Q 6- What is the range of byte data type is? A. -128 to 255 B. -128 to 256 C. -128 to 127 D. -127 to 128 Q 7- Which value can not store character data type. A. Digit B. Special character C. String D. Letter Q 8- Which of these class is used to read characters in a file? A. FileReader B. FileWriter C. FileInputStream

D. InputStreamReader Q 9- Which of these class can be used to implement input stream that uses a character array as the source? A. BufferedReader B. FileReader C. CharArrayReader D. FileArrayReader Q 10- Which of these classes can return more than one character to be returned to input stream? A. BufferedReader B. Bufferedwriter C. PushbachReader D. CharArrayReader Q 11- What is the output of the following program? import java.io.*; class filesinputoutput { public static void main(string args[]) { InputStream obj = new FileInputStream("inputoutput.java"); System.out.print(obj.available()); A. true B. false C. prints number of bytes in file D. prints number of characters in the file Q 12- What is the output of the following program? import java.io.*; class Chararrayinput { public static void main(string[] args) { String obj = "abcdef"; int length = obj.length(); char c[] = new char[length]; obj.getchars(0,length,c,0); CharArrayReader input1 = new CharArrayReader(c); CharArrayReader input2 = new CharArrayReader(c, 0, 3); int i; try { while ((i = input1.read())!= -1) { System.out.print((char)i); catch (IOException e) {

// TODO Auto-generated catch block e.printstacktrace(); A. abc B. abcd C. abcde D. abcdef Q 13- Which of these packages contain classes and interfaces used for input & output operations of a program? A. java.util B. java.lang C. java.io D. All of the mentioned Q 14- Which of these class is not a member class of java.io package? A. String B. StringReader C. Writer D. File Q 15- Which of these is specified by a File object? A. a file in disk B. directory path C. directory in disk D. None of the mentioned Q 16- What is the output of the following program? import java.io.*; class files { public static void main(string args[]) { File obj = new File("/java/system"); System.out.print(obj.getName()); A. java B. system C. java/system D. /java/system Q 17- Which is not a class invariant for this class? class Timestamp {

int year, month, day; A. 0<day<32 B. 0<month<13 C. 0<year<2500 D. if(month==2)day<30 E. a to String()method returns a string in the form"june032017 Q 18- Suppose that X, Y and Z are classes, Y extends X, Z extends Y, and variables x, y, and z are defined by: X x = new X(); Y y = new Y(); Z z = new Z(); Then which of these statements will compile and run: i. x = z; ii. z=x; iii. z = (Z)x; iv. y = (Z)x; A. None of them. B. Only i. C. Only i and iii. D. Only i, ii, and iii. E. Only i, iii, and iv. F. All four statements. Q 19- When does Exceptions in Java arises in code sequence? A. Run Time B. Compilation Time C. Can Occur Any Time D. None of the mentioned Q 20- What is the output of the program? class exception_handling { public static void main(string args[]) { try { int i, sum; sum = 10; for (i = -1; i < 3 ;++i) sum = (sum / i); catch(arithmeticexception e) { System.out.print("0"); System.out.print(sum);

A. 0 B. 05 C. Compilation Error D. Runtime Error Q 21- Which of these keywords is used to manually throw an exception? A. try B. finally C. throw D. catch Q 22-. Which of these keywords is not a part of exception handling? A. try B. finally C. thrown D. catch Q 23- What is the output of the program? class fibonacci { static int fib(int n) { /* Declare an array to store Fibonacci numbers. */ int f[] = new int[n+1]; int i; /* 0th and 1st number of the series are 0 and 1*/ f[0] = 0; f[1] = 1; for (i = 2; i <= n; i++) { f[i] = f[i-1] + f[i-2]; return f[n]; public static void main (String args[]) { int n = 9; System.out.println(fib(n));

A. 34 B. 35 C. 33 D. 32 Q 24- Java was developed by. A. Sun Microsystems B. Microsoft C. Oracle D. IBM E. Cisco Systems Q25- Which of the following statements is correct? A. Every line in a program must end with a semicolon. B. Every statement in a program must end with a semicolon. C. Every comment line must end with a semicolon. D. Every method must end with a semicolon. E. Every class must end with a semicolon. Q26- is a software that interprets Java bytecode. A. Java virtual machine B. Java compiler C. Java debugger D. Java API Q 27- Java compiler translates Java source code into. A. Java bytecode B. machine code C. assembly code D. another high-level language code Q 28- Computer can execute the code in. A. machine language B. assembly language C. high-level language D. none of the above Q 29- Which of the following lines is not a Java comment? A. /** comments */ B. // comments C. -- comments D. /* comments */ E. ** comments ** Q 30- If you forget to put a closing quotation mark on a string, what kind error will be raised? A. a compilation error B. a runtime error C. a logic error

Q 31- Which of the following statements are true? A. Text I/O is built upon binary I/O to provide a level of abstraction for character encoding and decoding. B. Text I/O does not involves encoding and decoding. C. Binary I/O does require conversions. D. Binary I/O is not more efficient than text I/O, because binary I/O does not require encoding and decoding. E. Binary files are dependent of the encoding scheme on the host machine and thus are portable. Q 32- Which of the following statements are true? A. A File object encapsulates the properties of a file or a path, but does contain the methods for reading/writing. B. You cannot use the PrintWriter class for outputting text to a file. C. You cannot use the Scanner class for reading text from a file. D. An input object is also called an input stream. Q 33- With which I/O class can you append or update a file? A. RandomAccessFile(), B. OutputStream() C. DataOutputStream() D. None of the above Q 34- A method must declare to throw. A. unchecked exceptions B. checked exceptions C. Error D. RuntimeException Q 35- Which of the following statements are true? A. You use the keyword throws to declare exceptions in the method heading. B. A method may declare to throw multiple exceptions. C. To throw an exception, use the keyword throw. D. If a checked exception occurs in a method, it must be either caught or declared to be thrown from the method. Q 36- Analyze the following code: class Test { public static void main(string[] args) throws MyException { System.out.println("Welcome to Java"); class MyException extends Error {

A. You should not declare a class that extends Error, because Error raises a fatal error that terminates the program. B. You cannot declare an exception in the main method. C. You declared an exception in the main method, but you did not throw it. D. The program has a compilation error. Q 37- What exception type does the following program throw? public class Test { public static void main(string[] args) { String s = "abc"; System.out.println(s.charAt(3)); A. ArithmeticException B. ArrayIndexOutOfBoundsException C. StringIndexOutOfBoundsException D. ClassCastException E. No exception Q 38- An instance of are unchecked exceptions. A. RuntimeException B. Exception C. Error D. Throwable E. NumberFormatException Q 39- The following code fragment reads in two numbers: Scanner input = new Scanner(System.in); int i = input.nextint(); double d = input.nextdouble(); What are the correct ways to enter these two numbers? A. Enter an integer, a space, a double value, and then the Enter key. B. Enter an integer, a double value, and then the Enter key. C. Enter a numeric value with a decimal point, a space, an integer, and then the Enter key. Q 40- The method returns a raised to the power of b. A. Math.power(a, b) B. Math.exponent(a, b) C. Math.pow(a, b) D. Math.pow(b, a) Q 41- What is the value of i printed? public class Test { public static void main(string[] args) { int j = 0;

int i = ++j + j * 5; System.out.println("What is i? " + i); A. 0 B. 1 C. 5 D. 6 Q 42- What is y displayed? public class Test { public static void main(string[] args) { int x = 1; int y = x + x++; System.out.println("y is " + y); A. y is 1. B. y is 2. C. y is 3. D. y is 4. Q 43- Suppose i is an int type variable. Which of the following statements display the character whose Unicode is stored in variable i? A. System.out.println(i); B. System.out.println((char)i); C. System.out.println((int)i); D. System.out.println(i + " "); Q 44- is the code with natural language mixed with Java code. A. Java program B. A Java statement C. Pseudocode D. A flowchart diagram Q 45- Analyze the following code. int count = 0; while (count < 100) { // Point A System.out.println("Welcome to Java!"); count++; // Point B // Point C

A. count < 100 is always true at Point A B. count < 100 is always true at Point B C. count < 100 is always false at Point B D. count < 100 is always true at Point C E. count < 100 is always false at Point C Q 46- Analyze the following statement: double sum = 0; for (double d = 0; d < 10;) { d += 0.1; sum += sum + d; A. The program has a compile error because the adjustment is missing in the for loop. B. The program has a compile error because the control variable in the for loop cannot be of the double type. C. The program runs in an infinite loop because d<10 would always be true. D. The program compiles and runs fine. Q 47- Which of the following loops prints "Welcome to Java" 10 times? A: for (int count = 1; count <= 10; count++) { System.out.println("Welcome to Java"); B: for (int count = 0; count < 10; count++) { System.out.println("Welcome to Java"); C: for (int count = 1; count < 10; count++) { System.out.println("Welcome to Java"); D: for (int count = 0; count <= 10; count++) { System.out.println("Welcome to Java"); A. BD B. ABC C. AC D. BC E. AB Q 48- Given the following four patterns,

Pattern A Pattern B Pattern C Pattern D 1 1 2 3 4 5 6 1 1 2 3 4 5 6 1 2 1 2 3 4 5 2 1 1 2 3 4 5 1 2 3 1 2 3 4 3 2 1 1 2 3 4 1 2 3 4 1 2 3 4 3 2 1 1 2 3 1 2 3 4 5 1 2 5 4 3 2 1 1 2 1 2 3 4 5 6 1 6 5 4 3 2 1 1 Which of the pattern is produced by the following code? for (int i = 1; i <= 6; i++) { for (int j = 6; j >= 1; j--) System.out.print(j <= i? j + " " : " " + " "); System.out.println(); A. Pattern A B. Pattern B C. Pattern C D. Pattern D Q 49- Suppose the input for number is 9. What is the output from running the following program? import java.util.scanner; public class Test { public static void main(string[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter an integer: "); int number = input.nextint(); int i; boolean isprime = true; for (i = 2; i < number && isprime; i++) { if (number % i == 0) { isprime = false; System.out.println("i is " + i); if (isprime) System.out.println(number + " is prime"); else System.out.println(number + " is not prime");

A. i is 3 followed by 9 is prime B. i is 3 followed by 9 is not prime C. i is 4 followed by 9 is prime D. i is 4 followed by 9 is not prime Q 50- Analyze the following code: public class Test { public static void main(string[] args) { System.out.println(xMethod(5, 500L)); public static int xmethod(int n, long l) { System.out.println("int, long"); return n; public static long xmethod(long n, long l) { System.out.println("long, long"); return n; A. The program displays int, long followed by 5. B. The program displays long, long followed by 5. C. The program runs fine but displays things other than 5. D. The program does not compile because the compiler cannot distinguish which xmethod to invoke.