CS56 final (E03) W15, Phill Conrad, UC Santa Barbara Wednesday, 03/18/2015. Name: Umail umail.ucsb.edu. Circle one: 4pm 5pm 6pm

Similar documents
CS56 Midterm Exam. E01, W16, Phill Conrad, UC Santa Barbara Wednesday, 02/10/2015

CS16 Midterm Exam 2 E02, 10W, Phill Conrad, UC Santa Barbara Tuesday, 03/02/2010

CS16 Midterm Exam 2 E02, 09F, Phill Conrad, UC Santa Barbara Wednesday, 11/18/2009

CS16 Midterm Exam 1 E01, 10S, Phill Conrad, UC Santa Barbara Wednesday, 04/21/2010, 1pm-1:50pm

E02, W16, Phill Conrad, UC Santa Barbara

CS8 Final Exam E03, 09M, Phill Conrad, UC Santa Barbara 09/10/2009

***PRACTICE EXAM 02 for*** CS16 Midterm Exam 2 E02, 09F, Phill Conrad, UC Santa Barbara Actual exam scheduled for: 11/18/2009

#101 Page: 1 Name: CS32 Midterm Exam. E01, W15, Phill Conrad, UC Santa Barbara

CS16 Final Exam E03, 10S, Phill Conrad, UC Santa Barbara Wednesday, 06/09/2010

CS32 Final Exam. E03, F15, Phill Conrad, UC Santa Barbara

Object Oriented Programming 2015/16. Final Exam June 28, 2016

CS32 Midterm Exam E01, F15, Phill Conrad, UC Santa Barbara Wednesday, 10/28/2015, 11am 12:15pm

NOTE: All references to Python on this exam mean Python 3, so you should answer accordingly.

CSCI 135 Exam #2 Fundamentals of Computer Science I Fall 2013

CSCI 135 Exam #2 Fundamentals of Computer Science I Fall 2013

CS 101 Fall 2006 Midterm 1 Name: ID:

COMPUTER SCIENCE DEPARTMENT PICNIC. Operations. Push the power button and hold. Once the light begins blinking, enter the room code

CMSC 331 Second Midterm Exam

CS 101 Exam 2 Spring Id Name

COE318 Lecture Notes Week 3 (Week of Sept 17, 2012)

Prelim One Solution. CS211 Fall Name. NetID

Agenda CS121/IS223. Reminder. Object Declaration, Creation, Assignment. What is Going On? Variables in Java

CS Exam 1 Review Suggestions

CS 11 java track: lecture 1

CSE 70 Final Exam Fall 2009

Learning objectives: Enhancing Classes. CSI1102: Introduction to Software Design. More about References. The null Reference. The this reference

CMSC 331 Second Midterm Exam

RAIK 183H Examination 2 Solution. November 10, 2014

CS121/IS223. Object Reference Variables. Dr Olly Gotel

Midterm Exam 2 CS 455, Spring 2011

1 Shyam sir JAVA Notes

Final Exam CS 251, Intermediate Programming December 13, 2017

CS32 Final Exam. E03, S15, Phill Conrad, UC Santa Barbara Tuesday, 06/08/2015, 8am 11am

B2.52-R3: INTRODUCTION TO OBJECT ORIENTATED PROGRAMMING THROUGH JAVA

1 Inheritance (8 minutes, 9 points)

INSTRUCTIONS TO CANDIDATES

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

CS3360 Design and Implementation of Programming Languages Final Exam May 16, pm to 12:45pm (2 hour and 40 minutes) NAME:

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)

CS2: Debugging in Java

CS365 Midterm -- Spring 2019

CS 101 Spring 2007 Midterm 2 Name: ID:

CS 101 Fall 2006 Midterm 3 Name: ID:

CS 455 Final Exam Fall 2015 [Bono] Dec. 15, 2015

B2.52-R3: INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING THROUGH JAVA

CS 251, Intermediate Programming Midterm Exam October 9, 2013

CS 101 Fall 2005 Midterm 2 Name: ID:

Review sheet for Final Exam (List of objectives for this course)

Largest Online Community of VU Students

RAIK 183H Examination 2 Solution. November 11, 2013

CSCI 201L Written Exam #1 Fall % of course grade

CS Exam 3 - Spring 2010

This exam is closed textbook(s) and closed notes. Use of any electronic device (e.g., for computing and/or communicating) is NOT permitted.

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

Announcements. 1. Forms to return today after class:

Chapter 5: Enhancing Classes

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

CSI Introduction to Software Design. Prof. Dr.-Ing. Abdulmotaleb El Saddik University of Ottawa (SITE 5-037) (613) x 6277

CS 2150 Exam 1, Spring 2018 Page 1 of 6 UVa userid:

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

COP 3330 Final Exam Review

References. Chapter 5: Enhancing Classes. Enhancing Classes. The null Reference. Java Software Solutions for AP* Computer Science A 2nd Edition

CS 162, Lecture 25: Exam II Review. 30 May 2018

1.00 Introduction to Computers and Engineering Problem Solving. Quiz 1 March 7, 2003

Array. Prepared By - Rifat Shahriyar

CS 113 MIDTERM EXAM 2 SPRING 2013

CSC System Development with Java. Exception Handling. Department of Statistics and Computer Science. Budditha Hettige

CS 1331 Exam 1. Fall Failure to properly fill in the information on this page will result in a deduction of up to 5 points from your exam score.

Oracle 1Z Java SE 8 Programmer I. Download Full Version :

Faculty of Science FINAL EXAMINATION

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

Introduction to Software Engineering: Tools and Environments. Session 9. Oded Lachish

CS 1331 Exam 1 ANSWER KEY

Queens College, CUNY Department of Computer Science. CS 212 Object-Oriented Programming in Java Practice Exam 2. CS 212 Exam 2 Study Guide

Getting It Right COMS W4115. Prof. Stephen A. Edwards Spring 2007 Columbia University Department of Computer Science

Chapter 1 Getting Started

COMP-202 Unit 9: Exceptions

CS 10, Fall 2015, Professor Prasad Jayanti

CS Exam 3 - Spring 2010

Midterm I - CSE11 Fall 2013 CLOSED BOOK, CLOSED NOTES 50 minutes, 100 points Total.

CS/B.TECH/CSE(New)/SEM-5/CS-504D/ OBJECT ORIENTED PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70 GROUP A. (Multiple Choice Type Question)

Prelim 1. CS 2110, October 1, 2015, 5:30 PM Total Question Name True Short Testing Strings Recursion

CSCI 136 Written Exam #0 Fundamentals of Computer Science II Spring 2013

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

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub

CS321 Languages and Compiler Design I. Winter 2012 Lecture 2

1 Method Signatures and Overloading (3 minutes, 2 points)

McGill University School of Computer Science COMP-202A Introduction to Computing 1

Practice Midterm 1. Problem Points Score TOTAL 50

Overriding המחלקה למדעי המחשב עזאם מרעי אוניברסיטת בן-גוריון

Repetition Structures

Condition-Controlled Loop. Condition-Controlled Loop. If Statement. Various Forms. Conditional-Controlled Loop. Loop Caution.

EECS168 Exam 3 Review

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

Throughout the exam, write concisely and underline key words or phrases. Have fun! Exam 2. Week 7 (Winter 2013). Dr. Yoder. Sec 031.

Name: Checked: Learn about listeners, events, and simple animation for interactive graphical user interfaces.

UMBC CMSC 331 Final Exam

Introduction to Programming System Design CSCI 455x (4 Units)

ext Total Score /20 /20 /15 /20 /25 /5 Grader

CS164: Programming Assignment 5 Decaf Semantic Analysis and Code Generation

Transcription:

CS56 final (E03) W15, Phill Conrad, UC Santa Barbara Wednesday, 03/18/2015 Name: Umail Address: @ umail.ucsb.edu Circle one: 4pm 5pm 6pm Please write your name only on this page. That allows me to grade your exams without knowing whose exam I am grading. This exam is closed book, closed notes, closed mouth, cell phone off, except for: You are permitted one sheet of paper (max size 8.5x11") on which to write notes These sheets will be collected with the exam, and might not be returned Please write your name on your notes sheet There are 100 points worth of questions on the exam, and you have 180 minutes (3 hrs) to complete the exam. A hint for allocating your time on your first pass through the exam: if a question is worth 4 points, spend no more than 4 minutes on it if a question is worth 10 points, spend no more than 10 minutes on it etc. If you do that, after you complete your first pass through the exam in 100 minutes, you'll still have over an hour to: revisit any questions where you need more time check your work.

2 Name: A 1. BRIEFLY explain each of the following concepts. For full credit, give a SHORT, PRECISE, RELEVANT answer. If your answer is too long and rambling, it may be penalized. (5 pts) Legacy code (5 pts) "DRY" code (5 pts) Refactoring 2. In Java Swing GUI programming, when writing a classs that implement the ActionListener interface, it is a very common practice to make the class as an "inner class". In THIS context, BRIEFLY answer the following questions: a. (5 pts) What does it mean to be an "inner class"? b. (5 pts) If the inner class implements ActionListener, what kind of thing is the "outer class" likely to be? c. (5 pts) Why is an inner class often used for classes that implement ActionListener? (Hint: the textbook describes a "special relationship" that is relevant here.)

3 Name: A The first few questions on this exam refer to the file Person.java, which appears on a separate handout along with this exam. 3. (5 pts) Suppose the tostring method were removed from the Person class. What would the output of the main program then look like? a. Since there is no tostring method, the program will not compile as written there would be syntax errors for lines 23 and 30. Therefore, there can be no output. Since Person doesn't "extend" any other class, there is no parent class for Person to inherit a tostring method from. b. The output will be something like the following (the hex numbers may vary). This is the default output of the tostring method of the Object class, which is inherited when there is no overridden tostring method. A: x = Person@20cf2c80 y = Person@1729854 B: x = Person@a6eb38a y = Person@69cd2e5f c. The output would be unchanged (as shown below) the tostring method for Object, by default, lists the contents of each field just as the tostring method we wrote for this class does. Hence the tostring method we wrote was redundant, and removing it is a helpful simplification. A: x = (Wilma,31) y = (Fred,32) B: x = (Betty,29) y = (Barney,29) 4. (5 pts) Consider the variable ageas it appears on line 5. Which statement is completely true about this variable? (Note: Some of the statements may be partially true, and partially false, while others are completely false. Only one is completely true.) a. It is a reference variable, and it is a formal parameter. So the reference itself is stored on the stack. b. It is a primitive variable, and it is a formal parameter. So its value is stored on the stack. c. It is a reference variable, and it is also a primitive variable. So the value is stored on the stack. d. It is a primitive variable, and it is also an instance variable. So the value is stored on the heap. e. It is a reference variable, and it is also an instance variable. So the reference is stored on the heap. 5. (5 pts) Consider the variable nameas it appears on line 20. Which statement is completely true about this variable? (Note: Some of the statements may be partially true, and partially false, while others are completely false. Only one is completely true.) a. It is a primitive variable, and it is a formal parameter. So the value is stored on the heap. b. It is a reference variable, and it is also an instance variable. So the reference itself is on the heap, and so is the object to which the references refers. c. It is a primitive variable, and it is also an instance variable. So the value is stored on the heap. d. It is a reference variable, and it is also a primitive variable. So the reference is stored on the heap, but the value referred to is stored on the stack. e. It is a reference variable, a local variable, and an argument to a method. So the reference itself is stored on the stack but the value it points to is on the heap. 6. (5 pts) Consider the variable age as it appears on line 13. Which statement is completely true about this variable? (Note: Some of the statements may be partially true, and partially false, while others are completely false. Only one is completely true.) a. It is a reference variable, and it is a local variable. So the reference itself is stored on the stack, but the object it refers to is on the heap. b. It is a reference variable, and it is also an instance variable. So the reference is stored on the heap, and the value referred to is also on the heap. c. It is a primitive variable, and it is also an instance variable. So the value is stored on the heap. d. It is a primitive variable, and it is a formal parameter. So the value is stored on the heap. e. It is a reference variable, and it is also a primitive variable. So the reference is stored on the heap, But the value referred to is stored on the stack. 7. (5 pts) When does the Person object (Fred, 32) become eligible for garbage collection? a. after line 20 is finished executing b. after line 21 is finished executing c. after line 23 is finished executing d. after line 27 is finished executing e. none of the above 8. (5 pts) At what line does the Person object (Wilma, 31) become eligible for garbage collection?

a. after line 20 is finished executing b. after line 21 is finished executing c. after line 23 is finished executing d. after line 27 is finished executing e. none of the above

4 Name: A The next few questions deal with the program PushCounter.java, found on a separate handout. One line of the code is missing at line 32. This program implements a simple GUI example where every time you push the button, the counter goes up by one. For example: Starting point: After first button press: After second button press: 9. (5 pts) The missing line of code in PushCounter.java at line 32 should be which of these? (multiple choice: circle one letter) a. public inner class ButtonListener implements ActionListener { b. public static void main(string [] args) { c. public class ButtonListener implements ActionListener { d. public class ButtonListener extends ActionListener { e. public static void ButtonListener(ActionEvent event) { 10. (5 pts) Suppose that you want the number to appear above the button, like this: What change can you make to the code to achieve that? In each case, you may assume that the necessary import statements are added to the top of the file. a. replace lines 27,28 with: this.setlayout(new BoxLayout(this,BoxLayout.Y_AXIS)); this.add(label); this.add(button); b. replace line 28 with: this.add(label); this.add(button); c. replace line 27,28 with: this.setlayout(new BorderLayout()); this.add(borderlayout.south,label); this.add(borderlayout.north,button); d. replace line 28 with: this.add(label); this.println("\n"); this.add(button); e. replace line 27,28 with: this.setlayout(new BoxLayout(this,BoxLayout.X_AXIS)); this.add(label); this.add(button);

5 Name: A 11. (5 pts) Suppose you are writing a program that implements a Swing GUI using a JFrame for example, the PushCounter class that appears on the previous page. When you run the program, suppose you get the following error: -bash-4.1$ java PushCounter Exception in thread "main" java.awt.headlessexception: No X11 DISPLAY variable was set, but this program performed an operation which requires it. at java.awt.graphicsenvironment.checkheadless(graphicsenvironment.java:173) at java.awt.window.(window.java:437) at java.awt.frame.(frame.java:419) at java.awt.frame.(frame.java:384) at javax.swing.jframe.(jframe.java:174) at PushCounter.main(PushCounter.java:15) -bash-4.1$ Which of the following choices best explains what is wrong, and what you need to do to fix the problem so that you will see the GUI shown in the pictures above instead of this error message? a. You are running in a shell that does not have access to an X11 server. If you are ssh'ing in from Mac or Linux, you need the -Y flag, or if running on Windows, you need to run your terminal (e.g. PuTTY) together with an X11 server for Windows such as XMing. b. A HeadlessException is being thrown. You need to import java.awt.headlessexception, and then use either try/catch, or declare that main throws HeadlessException. c. You should have typed ant run instead of java PushCounter d. The X11 DISPLAY variable is not set. You need to use import java.awt.display and then call Display.setDisplay("X11"); as the first line in your main program. e. There is an error in your build.xml file that is causing the program not to load properly. The next three questions refer to the following code listing 1 <?xml version="1.0" encoding="utf-8"?> 2 <project default="compile"> 3 4 <target name="compile" > 5 <mkdir dir="build" /> 6 <javac srcdir="src" destdir="build" debug="true" debuglevel="lines,source"> 7 <include name="**/*.java"/> 8 </javac> 9 </target> 10 11 <target name="run" depends="compile" > 12 <java classname="foo" fork="true" classpath="build" /> 13 </target> 14 15 </project> 12. (5 pts) Consider the word trueon line 6. What best describes this word? a. It is the name of an attribute b. It is the value of an attribute c. It is an Ant target d. It is an open tag e. It is the name of a self closing element 13. (5 pts) Consider the word include on line 7. What best describes this word? a. It is the name of an attribute b. It is the value of an attribute c. It is an Ant target d. It is an open tag e. It is the name of a self closing element

6 Name: A The next few questions do not depend on the code on any handout. Except where noted, consider each one as a stand alone question. 14. (5 pts) Assume the following code appears inside a main() method of a Java class. int x = 1; while (x) { } System.out.println("foo"); x++; Which of the following is true about this code? a. It will print "foo" on standard output, one "foo" per line, until the value of x exceeds the maximum value for an int (i.e. 2 32-1), at which point an Exception will be thrown. b. It is a syntax error int values cannot be treated as boolean values in Java c. It will print "foo" on standard output, one "foo" per line, forever, or until the program is terminated d. It will print "foo" on standard output, one "foo" per line, until the value of x wraps around to the largest negative integer, i.e. -2 32, and then climbs back up to zero. At that point, the condition will be false and the loop will halt. 15. (5 pts) Assume that the following line of code appears inside a java main() method. Dog [] pets = new Dog[7]; Which of the following is a true statement? a. petsis a local variable on the stack that refers to an Array object. This is an array of seven Dog objects, pets[0] through pets[6] each of which is allocated on the heap. This statement is not legal if the Dog class does not contain a default constructor. b. petsis a local variable on the stack that refers to an Array object. That array object is on the heap. The array object contains seven Dog references pets[0] through pets[6], each of which is initially null. No Dog objects are created by this statement. 16. (5 pts) Which of the following is true about normal git workflow: a. The normal sequence is "git push", "git add", "git commit" b. The normal sequence is "git push", "git commit", "git add" c. The normal sequence is "git add", "git commit", "git push" d. The normal sequence is "git add", "git push", "git commit" e. The normal sequence is "git commit", "git add", "git push" End of Final (E03) Total Points: 100