CISC474 Final Exam
E03, 07S, Phill Conrad, University of Delaware
05/21/2007

Name: ________________________________________________________________


UD Email: _____________________________________________@ udel.edu

About this exam

A hint about allocating your time:

How to get a good grade:

PLEASE!


Circle here which four questions you are submitting.
1 2 3 4 5 6

Choose any four of these six questions.

  1. (25 pts) Below are two ways that one could do a query in JDBC.
    Both have been tested, and correctly return the result set.

    Explain as clearly as possible which way is preferred, and precisely why.

    Method One:

    // Create a statement for SQL queries
    
    try {
        myStmt = myCon.createStatement();
    }
    catch (Exception e){
        e.printStackTrace();
        return brands;
    }
    
    // Set up the query.  
    
    String tableName = prefix_ + "Beers";
    String query = "SELECT beer, color FROM " + tableName 
                 + "  WHERE color='" + color + "'";
    
    ResultSet rs;
    
    try {
        rs = myStmt.executeQuery(query);
    }
    catch (Exception e) {
        e.printStackTrace();
        return brands;
    }  
      
      

    Method Two:

    // Set up the query.  
    
    String tableName = prefix_ + "Beers";
    String query = "SELECT beer, color FROM " + tableName + "  WHERE color=?";
      
    // Stick the value of "color" in where the first ? appears, and exec the query
    
    ResultSet rs;
    try {
        PreparedStatement prepStmt = myCon.prepareStatement(query);
        prepStmt.setString(1, color);
        rs = prepStmt.executeQuery();
    }
    catch (Exception e) {
        e.printStackTrace();
        return brands;
    }
    
  2. (25 pts) The following lines of code appear in the H09 example program

    String jdbcURL = getServletContext().getInitParameter("jdbcURL");
    String mySQLuser = getServletContext().getInitParameter("mySQLuser");
    String mySQLpw = getServletContext().getInitParameter("mySQLpw");
      

    Answer the following questions about these lines of code:

    1. (5 pts) Could these lines appear in a controller servlet that is part of an MVC webapp? Why or why not?
    2. (5 pts) Could these lines appear in a JSP that is part of the view for an MVC webapp? Why or why not?
    3. (5 pts) Could these lines appear in a model class that is part of an MVC web-app? Why or why not?
    4. (5 pts) In what source file would you look for the definitions of jdbcURL, mySQLuser, and mySQLpw (i.e. the actual values of these, such as jdbc:mysql://cisc474.acad.cis.udel.edu/pconrad, pconrad, and 97s8d9f7s, respectively?
    5. (5 pts) More specifically, exactly where in that source file would the definitions of these three things appears, and (roughly) what would these definitions look like? (I'll be forgiving about exact syntax details—its the general concept that I'm looking for here.)

     

  3. (25 pts) In homework H03, and homework H05, you were asked to validate your web pages using validator.w3.org. Briefly explain what validation is. In your answer, include the following points:

    1. (5 pts) What a <!DOCTYPE> declaration is, and what it has to do with validation.
    2. (10 pts) Cite at least two specific examples of common validation errors—things that many HTML authors write.
    3. (10 pts) If a web page looks ok in both IE and Firefox that doesn't necessarily mean it is valid. But if it looks ok in both IE and Firefox—and indeed, in most every browser we test it on—why should we care whether the HTML is "valid" or not? Explain.
  4. Debugging is an important skill in working with web applications. Debugging techniques will vary from technology to technology, but we've learned some specific ones relating to working with Tomcat and SQL.

    Suppose you find that when you access a screen in your web app that you "know" should produce a particular result—for example a list of all the "dark beers" in your database—but instead, you get an empty list.

    1. (5 pts) What can you do to make sure that the database itself is set up properly (independent of the web app)?

    2. (5 pts) Where (specifically) can you look to see if there is a stack trace being generated by some run time error deep inside your web app?

    3. (5 pts) Suppose you suspect that an error is your model class is causing the problem. You make a change and recompile. But nothing changes. So you suspect that perhaps your changes are "not taking"—that there is perhaps a mismatch between the code actually running on the server, and the code that you are looking at in your editor.

      What can you do to make absolutely sure that the code running on the Tomcat server is actually the same as the source code you are looking? (Don't just say "redeploy", or stop and restart the server—I want something even more specific and foolproof—I want close to 100% certainty!)

    4. (5 pts) Suppose you are using a build.xml file similar to the build.xml file supplied with H08 and H09. Is it sufficient, after each time you make a change, to just run ant compile? How about ant create-war? Explain.

    5. (5 pts) Describe at least one other useful Java/SQL/Ant/Tomcat debugging technique, or a problem and its solution.
      By other, I mean describe one that is different from the ones you've referred to so far in your answer to this question.

     

  5. (25 pts) In both Chapter 1 and Chapter 3 of your textbook, the text recommends a clean separation between a development environment, and a deployment environment. Explain why. In your answer, include:

    1. (10 pts) A clear description of the purpose of each environment—one that makes it clear what the difference between them is.
    2. (10 pts) A explanation of the rationale for keeping these two environments separate.
    3. (5 pts) A brief explanation of the downside of having these two separate environments—i.e. what traps a programmer can fall into if he/she isn't aware of this separation.
  6. (25 pts) Albert Einstein is often quoted as having said: You do not really understand something unless you can explain it to your grandmother. This question is in that spirit.

    Your friend “Chris” has asked for your help. Chris is a smart businessman, but is not particularly tech-savvy. Chris wants to hire someone to do some maintenance on the web site for his company. He knows that the current site is based on “JSPs” but he doesn't’t really know what those are. He tried to hire you, but your work load is too much at the moment; you know you don’t really have time to help him out. However, you do agree to sit in on the interviews of the web developers who have applied for the job.

    The first person to apply has a really nice looking portfolio. The web sites he says he developed look great. Your friend is very impressed as he looks through the sites the candidate shows him. So, your friend asks you if you have any questions for the candidate. You start with an easy one, just to break the ice: “Tell me, how did you learn HTML?”

    He says, “well, to be honest, I never took a formal class. I just did a ‘view source’ on a bunch of web pages that I thought looked good, and sort of figured out how they worked, and picked up HTML that way. As you can see, my web pages look pretty snazzy, even though I never took a formal class. Here see, you can do ’view source’ on any web page and read how it is coded.” At this the candidate shows a view source, and shows your friend how the tags line up with some of the elements on the rendered page. Your friend is getting more and more impressed.

    You : “Very clever. Tell me though, my friend also needs someone who can maintain Java Server Pages—you know, JSPs. You've shown us a bunch of JSP based sites as part of your portfolio. Did you create those sites too?”

    The candidate: “Yes, I sure did.”

    You: "How did you learn JSP?

    Candidate: "Exactly the same way— just found a bunch of sites that used JSPs, and then did “view source” and figured out they worked.”

    You: “Really? You learned not just static HTML, but also JSPs by doing ’view source’? Are you sure?”

    Candidate: “Yup, sure did. Took me a while to figure it out the JSP part, but eventually I got it.”

    You “Ah, very good—well I think that’s all we need to know.”

    Your friend is all smiles, and you and he both thank the candidate for stopping by. Once the candidate leaves the room, you turn to your friend and say: “That candidate is a bald faced liar, and technically incompetent. Under no circumstances should you hire him.”

    Your friend is taken aback. “That’s a pretty serious charge. How do you know this after only asking him four questions?” What do you tell your friend?

    Note: If you understand how JSPs work, it pretty simple to work out that the candidate is lying, and furthermore that he is not technically competent enough to realize that the lie is easy to spot. However, for this question, a quick explanation in technical terms is NOT sufficient for full credit. Having the technical facts correct will only earn you half the points.

    For full credit, you will be graded not only on the technical content of your question, but how well you explain it in terms that a non-technical person can understand. Keep in mind that your friend won't understand terms like "compiler", "container", "source code", "Tomcat", etc. You friend isn't stupid—he's a very successful businessman. But you won't communicate with him if you talk in "geek speak". And it is important that he fully understands—“trust me, I'm an expert” is not going to cut it here.

    Let's assume, to make things easier, that your friend did take one computer class in programming in BASIC a zillion years ago, and vaguely remembers things like a “for loop” and “input” and “output”. So you can use that as a point of reference. He's also seen the HTML code— the candidate did a view source, and showed him how the tags like <table> correspond with the table on the page. He also understands that a computer has files on it, and that the files are stored on the hard disk. He sort of gets, too, that information on web pages comes from some place called a “server” out there on the network somehow, and makes its way to his computer, though he is very hazy on the details.

    That's all you have to go on. Good luck!

End of Exam