You are on page 1of 10

Final Score _______________

Name ____________________________ ID __________________________ Extra Credit _______________

Section (circle one): TTh 8:00-9:20 TTh 9:30-10:50 TTh 11:00-12:20

CSCI 201L Written Exam #2


Spring 2018
15% of course grade

1. Inheritance – One of the problems with multiple inheritance in C++ can be seen in
the code below. Some people may argue that Java supports multiple inheritance since
it allows inheriting from multiple interfaces simultaneously. Explain how the
ambiguity problem shown in the C++ code below will not occur in Java. (1.0%)

1 #include <iostream>
2 using namespace std;
3 class Email_Reader {
4 public:
5 void send_email() {
6 cout << "Email sending email";
7 }
8 };
9 class Telephone {
10 public:
11 void send_email() {
12 cout << "Telephone sending email";
13 }
14 };
15 class IPhone : public Telephone, public Email_Reader {
16 };
17
18 void main() {
19 IPhone ip;
20 ip.send_email(); // this line is ambiguous
21 }

2. Garbage Collection – Why do you think the creators of Java didn’t make the garbage
collector preempt currently-executing threads? (0.5%)

CSCI 201L Written Exam #2


Spring 2018
1/10
3. HTML and JSP – Your friend from UCLA asked you to help him debug his code.
He is trying to have the HTML page submit the form to a JSP and have the form data
displayed from the JSP. It currently is not working. Explain the problem and fix it.
(0.5% + 0.5%)

<!‐‐ index.html ‐‐> 
<html> 
  <head> 
    <title>Question 3</title> 
  </head> 
  <body> 
    <form name="myform" action="submit.jsp"> 
      Name <input type="text" name="name" /><br /> 
      School <input type="text" name="school" /><br /> 
      <input type="submit" value="Submit" /> 
    </form> 
  </body> 
</html>
<%‐‐ submit.jsp ‐‐> 
<%@ page language="java" %> 
<html> 
  <head> 
    <title>Question 3</title> 
  </head> 
  <body> 
    <script language="JavaScript"> 
      document.write(document.myform.name.value); 
      document.write(document.myform.school.value); 
    </script> 
  </body> 
</html>

4. JavaScript and AJAX – The third parameter to the open function on the
XMLHttpRequest object is a boolean value representing whether the request will
be made synchronously (false) or asynchronously (true). Why would a programmer
ever want to make a synchronous AJAX call? (1.0%)

CSCI 201L Written Exam #2


Spring 2018
2/10
5. Concurrent Computing – Your friend has a single core single CPU machine. He
told you that he wrote a multi-threaded merge sort algorithm that runs twice as fast as
the single-threaded version. Do you believe your friend? Why or why not? (0.5% +
0.5%)

6. Software Engineering – Give two reasons why pair programming with junior to
mid-range programmers could be more productive than two programmers working
independently. (0.25% + 0.25%)

Reason #1

Reason #2

7. WebSockets – AJAX provides a way to dynamically update a web page without


requiring the entire page to be reloaded. This is also one of the benefits of
WebSockets. Give another benefit provided by WebSockets that is not a benefit of
AJAX. (0.5%)

CSCI 201L Written Exam #2


Spring 2018
3/10
8. Networking Theory – Assume you are given the following IP address and subnet
mask.

IP – 156.87.146.27
IP – 1001 1100 0101 0111 1001 0010 0001 1011
Subnet Mask – 255.255.240.0
Subnet Mask – 1111 1111 1111 1111 1111 0000 0000 0000

a. What class IP address is given? (0.25%)

b. What is the network address? (0.5%)

c. Is the IP address public or private? (0.25%)

d. How many hosts can be on the network? (0.5%)

e. How many hosts can be on the subnetwork? (0.5%)

f. What is the network and subnetwork combination? (0.25% + 0.25%)


Binary (only 0s and 1s)

Decimal

g. What are the first and last IP addresses that could be assigned to hosts in the
subnetwork? (0.25% + 0.25%)
First Assignable IP Address (in decimal, not binary)

Last Assignable IP Address (in decimal, not binary)

CSCI 201L Written Exam #2


Spring 2018
4/10
9. Locks – Look at the following code, then answer the questions that follow the code.

1  import java.util.concurrent.locks.Lock; 
2  import java.util.concurrent.locks.ReentrantLock; 
3  public class Question9 { 
4  private Lock l = new ReentrantLock(); 
5  public void a() { 
6    try { 
7      l.lock(); 
8      System.out.println("a"); 
9    } finally { 
10      l.unlock(); 
11    } 
12  } 
13   
14  public void b() { 
15    try { 
16      l.lock(); 
17      System.out.println("b1"); 
18      a(); 
19      System.out.println("b2"); 
20    } finally { 
21      l.unlock(); 
22    } 
23  } 
24   
25  public static void main(String [] args) { 
26    Question9 q9 = new Question9(); 
27    q9.a(); 
28    q9.b(); 
29  } 
30 } 

a. What is the output of the above code? (0.5%)

b. If the variable l was not reentrant, what would the output of the code be? (0.5%)

CSCI 201L Written Exam #2


Spring 2018
5/10
10. Locks and Monitors – Look at the following code then answer the questions below.

1  import java.util.concurrent.locks.Lock; 
2  import java.util.concurrent.locks.ReentrantLock; 

4  public class Question10 extends Thread { 
5  private int num; 
6  private Lock lock = new ReentrantLock(); 

8  public Question10(int num) { 
9    this.num = num; 
10  } 
11  public void bar() { 
12    lock.lock(); 
13    try { 
14      System.out.println(num + "bar 1"); 
15      System.out.println(num + "bar 2"); 
16    } finally { 
17      lock.unlock(); 
18    } 
19  } 
20  public void run() { 
21    System.out.println(num + "foo"); 
22    bar(); 
23  } 
24  public static void main(String [] args) { 
25    for (int i=0; i < 100; i++) { 
26      Question10 q10 = new Question10(i); 
27      q10.start(); 
28    } 
29  } 
30 } 

a. Give two rules concerning the output of the above program. In other words,
provide two statements that will always be true about the output. (0.5% + 0.5%)
Rule #1

Rule #2

b. Is the following portion of the output possible based on the above code? (0.5%)
 
15bar 1 
14bar 1 
15bar 2 
14bar 2

CSCI 201L Written Exam #2


Spring 2018
6/10
11. Databases and SQL – Answer the following questions concerning the database
below.

Here is the University table.

Here is the Department table. Here is the Ranking table.

a. Write the SQL code to get the departments that have been ranked at each
university. You will not return the rank. In other words, the following table
should be returned by the SELECT statement. It must be returned in the same
order as well. (0.5%)

CSCI 201L Written Exam #2


Spring 2018
7/10
b. Draw the table that is returned from the following query. (0.5%)

SELECT u.longname, d.deptname, r.rank


FROM University u, Department d, Ranking r
WHERE u.universityID=r.universityID
AND d.departmentID=r.departmentID
ORDER BY d.deptname, r.rank;

12. Parallel Programming – With four cores in a single CPU computer, even with the
most optimized parallel algorithm, you won’t be able to get a four-time improvement
in the running time. Give two reasons why this is the case. (0.5% + 0.5%)
Reason #1

Reason #2

13. Distributed Computing – Parallel and distributed computing are both used to make a
program execute faster. What is the difference between parallel and distributed
computing? (0.5%)

CSCI 201L Written Exam #2


Spring 2018
8/10
14. Producer/Consumer – The Producer/Consumer problem experienced deadlock when
trying to solve it with two monitors. Explain the Producer/Consumer problem and
how to solve it. (1.0% + 0.5%)

CSCI 201L Written Exam #2


Spring 2018
9/10
Extra Credit Questions
Extra credit is applied after the curve so does not affect other students.

Extra Credit (0.25%) – What was the most memorable lecture from this semester?
What made it memorable to you?

Extra Credit (0.25%) – Fill in the following table with one checkmark in each row
answering the following question. Do you think the amount of coverage of each topic
in the class was too little, just right, or too much?

Topic Too little coverage Perfect amount of Too much


coverage coverage
Java basics
HTML, CSS,
JavaScript
JSP, Servlets
Networking
Databases, JDBC
Multi-threading
Concurrency issues
(monitors, locks,
conditions,
semaphores)

Please explain.

CSCI 201L Written Exam #2


Spring 2018
10/10

You might also like