Multiple Choice Questions: Identify the choice that best completes the statement or answers the question. (15 marks)

Similar documents
Midterm assessment - MAKEUP Fall 2010

F I N A L E X A M I N A T I O N

CSCI 136 Written Exam #1 Fundamentals of Computer Science II Spring 2015

RAIK 183H Examination 2 Solution. November 11, 2013

G51PGP Programming Paradigms. Lecture 009 Concurrency, exceptions

Virtualians.ning.pk. 2 - Java program code is compiled into form called 1. Machine code 2. native Code 3. Byte Code (From Lectuer # 2) 4.

First Name: AITI 2004: Exam 2 July 19, 2004

RAIK 183H Examination 2 Solution. November 10, 2014

PART1: Choose the correct answer and write it on the answer sheet:

CS108, Stanford Handout #22. Thread 3 GUI

GUI and its COmponent Textfield, Button & Label. By Iqtidar Ali

First Name: AITI 2004: Exam 2 July 19, 2004

JRadioButton account_type_radio_button2 = new JRadioButton("Current"); ButtonGroup account_type_button_group = new ButtonGroup();

Graphical User Interfaces (GUIs)

COURSE DESCRIPTION. John Lewis and William Loftus; Java: Software Solutions; Addison Wesley

Frames, GUI and events. Introduction to Swing Structure of Frame based applications Graphical User Interface (GUI) Events and event handling

CSCI 136 Written Exam #2 Fundamentals of Computer Science II Spring 2015

Concurrency and Java Programming

Come & Join Us at VUSTUDENTS.net

Classes and Objects 3/28/2017. How can multiple methods within a Java class read and write the same variable?

Exercise Session Week 8

Exercise Session Week 8

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

OOP Assignment V. For example, the scrolling text (moving banner) problem without a thread looks like:

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

G51PGP Programming Paradigms. Lecture 008 Inner classes, anonymous classes, Swing worker thread

Lecture 9: Introduction to Monitors

Java Intro 3. Java Intro 3. Class Libraries and the Java API. Outline

Goals. Lecture 7 More GUI programming. The application. The application D&D 12. CompSci 230: Semester JFrame subclass: ListOWords

COMP 250 Winter 2011 Reading: Java background January 5, 2011

Java Threads. COMP 585 Noteset #2 1

CONTENTS. Chapter 1 Getting Started with Java SE 6 1. Chapter 2 Exploring Variables, Data Types, Operators and Arrays 13

Full file at Chapter 2 - Inheritance and Exception Handling

What Is an Event? Some event handler. ActionEvent. actionperformed(actionevent e) { }

CHETTINAD COLLEGE OF ENGINEERING & TECHNOLOGY JAVA

1 Looping Constructs (4 minutes, 2 points)

2IS45 Programming

The JFrame Class Frame Windows GRAPHICAL USER INTERFACES. Five steps to displaying a frame: 1) Construct an object of the JFrame class

Threads Chate Patanothai

CS180 Review. Recitation Week 15

Chair of Software Engineering. Java and C# in Depth. Prof. Dr. Bertrand Meyer. Exercise Session 8. Nadia Polikarpova

JFrame & JLabel. By Iqtidar Ali

H212 Introduction to Software Systems Honors

MIT AITI Swing Event Model Lecture 17

CSCI 201L Midterm Written Summer % of course grade

Do not turn to the next page until the start of the exam.

Packages: Putting Classes Together

CS180 Spring 2010 Exam 2 Solutions, 29 March, 2010 Prof. Chris Clifton

Single processor CPU. Memory I/O

AP CS Unit 11: Graphics and Events

Do not turn to the next page until the start of the exam.

Java, Swing, and Eclipse: The Calculator Lab.

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Project. Threads. Plan for today. Before we begin. Thread. Thread. Minimum submission. Synchronization TSP. Thread synchronization. Any questions?

CS506 Web Design & Development Final Term Solved MCQs with Reference

CS61B, Spring 2003 Discussion #17 Amir Kamil UC Berkeley 5/12/03

Concurrent Computing CSCI 201 Principles of Software Development

Le L c e t c ur u e e 7 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Multithreading

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Building a GUI in Java with Swing. CITS1001 extension notes Rachel Cardell-Oliver

Introduction to the JAVA UI classes Advanced HCI IAT351

Answer on question #61311, Programming & Computer Science / Java

Final Examination Semester 2 / Year 2011

Object-Oriented Software Engineering Re-exam, 2012 (Also Object-Oriented Analysis, Design and Programming, Re-exam, 2012)

Dr. Hikmat A. M. AbdelJaber

SampleApp.java. Page 1

Introduction to Graphical User Interfaces (GUIs) Lecture 10 CS2110 Fall 2008

CS506 Web Programming and Development Solved Subjective Questions With Reference For Final Term Lecture No 1

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

CS 180 Fall 2006 Exam II

CMSC 331 Second Midterm Exam

SINGLE EVENT HANDLING

Process Characteristics. Threads Chapter 4. Process Characteristics. Multithreading vs. Single threading

Threads Chapter 4. Reading: 4.1,4.4, 4.5

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

Name Section. CS 21a Introduction to Computing I 1 st Semester Final Exam

Graphics User Defined Forms, Part I

Systems Programming. Bachelor in Telecommunication Technology Engineering Bachelor in Communication System Engineering Carlos III University of Madrid

Swing from A to Z Some Simple Components. Preface

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Multithreaded Programming

15CS45 : OBJECT ORIENTED CONCEPTS

Table of Contents. Chapter 1 Getting Started with Java SE 7 1. Chapter 2 Exploring Class Members in Java 15. iii. Introduction of Java SE 7...

CS 180 Final Exam Review 12/(11, 12)/08

Lab 4. D0010E Object-Oriented Programming and Design. Today s lecture. GUI programming in

PROGRAMMING DESIGN USING JAVA (ITT 303) Unit 7

Lecture 5: Java Graphics

Reading from URL. Intent - open URL get an input stream on the connection, and read from the input stream.

SE1021 Exam 2. When returning your exam, place your note-sheet on top. Page 1: This cover. Page 2 (Multiple choice): 10pts

OBJECT ORIENTED PROGRAMMING TYm. Allotted : 3 Hours Full Marks: 70

Question 1. Show the steps that are involved in sorting the string SORTME using the quicksort algorithm given below.

Part IV Other Systems: I Java Threads

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Object-oriented programming in Java (2)

Computation Abstractions. Processes vs. Threads. So, What Is a Thread? CMSC 433 Programming Language Technologies and Paradigms Spring 2007

M257 Putting Java to work

Swing - JTextField. Adding a text field to the main window (with tooltips and all)

Casting -Allows a narrowing assignment by asking the Java compiler to "trust us"

Unit III Rupali Sherekar 2017

JAVA EXAMPLES - SOLVING DEADLOCK

Transcription:

M257 MTA Spring2010 Multiple Choice Questions: Identify the choice that best completes the statement or answers the question. (15 marks) 1. If we need various objects that are similar in structure, but not exactly the same, we use. a. composition c. inheritance b. overloading d. None of the above 2. A mutator method is also known as a method. a. main c. private b. setter d. getter 3. Default access level is sometimes known as ' access'. a. public c. package b. protected d. private 4. Which of the following exception types must be caught or declared by the programmer? a. Error c. FileNotFoundException b. RunTimeException d. All of the above 5. HashMap class belongs to package. a. java.lang c. java.io b. java.util d. java.swing 6. ArrayList<E> class is a(an) class. a. abstract c. generic b. object wrapper d. All of the above 7. In Java, allow the primitive data types to be treated as objects. a. abstract classes c. generic classes b. object wrappers d. None of the above 8. Which of the following Java GUI components is known as a container? a. JTextField c. JList b. JPanel d. JButton 9. Which of the following events can be handled by a MouseListener interface? a. mouse button is pressed c. mouse button is released b. mouse enters a component d. All of the above 10. The Java system has a component known as the that makes decisions about which thread to run next. a. schedular c. event handler b. runnable d. None of the above

Problem Solving: Answer the following questions 1. Write Java code to read a line of text from the user and then display it. Use the BufferedReader class to read the input. 2. Re-write the following code using if-else statement: char c;... switch(c){ case 'y': case 'Y': System.out.println("Yes"); break; case 'n': case 'N': System.out.println("No"); break; default: System.out.println("Wrong answer!"); 3. Write a temperature conversion program that converts from Celsius to Fahrenheit. The Celsius temperature should be entered from the keyboard (via a JTextField). A JLabel should be used to display the converted temperature. Your program should have an interface similar to the following one: Your interface should have the following characteristics/behaviors: - Title: Temp Conversion - Size: 250 x 100 - Layout manager: FlowLayout - The program is terminated when the x button is pressed.

4. (a) What is the output of the following code? Justify your answer. public class Counter extends Thread { private int num; public Counter(int n) { num = n; public void run() { for (int i = 0; i < 5; i++) { System.out.print(num); try { Thread.sleep(10); catch (InterruptedException ex) { public static void main(string[] args) { Counter c1 = new Counter(1); Counter c2 = new Counter(2); c1.start(); c2.start(); (b) Modify the above class so that it uses alternative technique for creating threads. In your answer, underline the changes you make in the above code. Essay: Answer the following questions. 1. What is the difference between the method sleep and the method wait? 2. (a) When an exception is declared in the method header, what happens if the code throws that exception? (b) Briefly explain the meaning of propagating an exception. (c) What happens if the exception mentioned in (a) is not handled in any try-catch statements in the program? 3. In Java event handling, briefly explain the advantage of spearating the source of the event (i.e. the visual components) and the code where the event is handled. 4. List one similarity and one difference between the class ArrayList and arrays.

M257 MTA Spring2010 Answer Section MULTIPLE CHOICE 1. ANS: C 2. ANS: B 3. ANS: C 4. ANS: C 5. ANS: B 6. ANS: C 7. ANS: B 8. ANS: B 9. ANS: D 10. ANS: A PROBLEM 1. ANS: PTS: 3 KEY: Unit 4 2. ANS: char c;... if(c=='y' c=='y') System.out.println("Yes"); else if(c=='n' c=='n') System.out.println("No"); else System.out.println("Wrong answer!"); PTS: 10 KEY: Unit 6 3. ANS: package MTA; import java.awt.*; import java.awt.event.actionevent; import java.awt.event.actionlistener; import javax.swing.*; public class TempConversion extends JFrame{ JButton tofeh; JTextField cel;

JLabel result; public TempConversion() { //frame properties setdefaultcloseoperation(jframe.exit_on_close); settitle("temp Conversion"); setsize(250, 100); setlayout(new FlowLayout()); //creating gui elements tofeh = new JButton("Covert to Fahrenheit"); cel = new JTextField(10); result = new JLabel(" "); //adding gui elements add(cel); add(result); add(tofeh); //add events public static void main(string[] args) { new TempConversion().setVisible(true); PTS: 10 KEY: Unit 6 4. ANS: (a) The ouput would be something like the following: 1122211122 This output could be different (e.g. 1111122222, 1112211222, etc). Justification: No one thread had exclusive access to the CPU for its entire execution. It is not the case that the threads take it in turns to run. One thread has access for a certain amount of time and then another thread has access, and so on. (b) The alternative code is as follows (changes underlined). public class Counter implements Runnable { private int num; public Counter(int n) { num = n; public void run() { for (int i = 0; i < 5; i++) { System.out.print(num); try { Thread.sleep(10); catch (InterruptedException ex) { public static void main(string[] args) { Counter c1 = new Counter(1); Counter c2 = new Counter(2); Thread t1 = new Thread(c1); Thread t2 = new Thread(c2) t1.start(); t2.start(); PTS: 10 KEY: Unit 8

ESSAY 1. ANS: When a thread invokes the sleep method it holds onto any lock that it has got through having entered a synchronized method. This prevents any other thread getting access to this method (or any other synchronized methods in the same object) while it sleeps. However, with wait, the thread releases the lock it has on the object and so allows other threads to have access while it is waiting. PTS: 4 KEY: Unit 8 2. ANS: (a) then the exception will be passed to the method that invoked this method. (b) Any exception not handled in a particular method will be passed up a chain of invoking methods to a higher level, until an appropriate exception handler is found. This is known as propagating the exception. (c) If no handler exists at any level for this exception, then the program terminates with an error message PTS: 3 KEY: Unit 4 3. ANS: If, at a later date, either the graphical user interface or the processing code has to change then these changes can be localized. PTS: 3 KEY: Unit 7 4. ANS: Similarities - Both can store a number of references - and the data can be accessed via an index. Differences - The ArrayList can automatically increase in capacity as necessary - The ArrayList object requests more space from the Java run-time system, if necessary. - The ArrayList is not ideal in its use of memory. As soon as an ArrayList requires more space than its current capacity, the system will allocate more memory space for it. The extension is more than required for the items about to be added. So there will often be empty locations within an ArrayList that is, the size will often be less than the capacity. PTS: 4 KEY: Unit 5